
/*
 * php_guichan.c
 * This file is part of php_guichan extension for PHP
 *
 * Copyright (C) 2012 - likewu
 *
 * php_guichan extension for PHP is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * php_guichan extension for PHP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with php_guichan extension for PHP; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, 
 * Boston, MA  02110-1301  USA
 * 
 * Linking php_guichan extension for PHP statically or dynamically with other modules is 
 * making a combined work based on php_guichan extension for PHP. Thus, the
 * terms and conditions of the GNU General Public License cover the
 * whole combination.
 *
 * In addition, as a special exception, the copyright holders of 
 * php_guichan extension for PHP give you permission to combine php_guichan extension for PHP with free
 * software programs or libraries that are released under the GNU 
 * LGPL and PHP License, and with code included in the standard 
 * release of libSDL under the LGPL 
 * (or modified versions of such code, with unchanged license), and
 * libraries and with code included in the standard release of PHP under
 * the PHP License.
 *
 * You may copy and distribute such a system following the terms 
 * of the GNU GPL for @extname and the licenses 
 * of the other code concerned {, provided that you include the source 
 * code of that other code when and as the GNU GPL requires distribution
 * of source code}.
 * 
 * Note that people who make modified versions of php_guichan extension for PHP are not 
 * obligated to grant this special exception for their modified 
 * versions; it is their choice whether to do so. The GNU General 
 * Public License gives permission to release a modified version 
 * without this exception; this exception also makes it possible to 
 * release a modified version which carries forward this exception.
 */
		

#include <guichan.hpp>
#include <guichan/sdl.hpp>
#include <iostream>

#include "phpkeylistener.hpp"
#include "phpmouselistener.hpp"

namespace globals
{
    gcn::Gui* gui;
}
	
// Inclusions.
#include "php_guichan.h"

// Globals
//ZEND_DECLARE_MODULE_GLOBALS(guichan)
// End Globals

/*******************************
 * Resources
 *******************************/
static int le_cdrom;
#define le_cdrom_name "SDL CD-Rom"
static int le_timer;
#define le_timer_name "SDL Timer"
static int le_surface;
#define le_surface_name "SDL Surface"
static int le_pixelformat;
#define le_pixelformat_name "SDL PixelFormat"
static int le_cursor;
#define le_cursor_name "SDL Cursor"
static int le_overlay;
#define le_overlay_name "SDL Overlay"
static int le_joystick;
#define le_joystick_name "SDL Joystick"
static int le_mutex;
#define le_mutex_name "SDL Mutex"
static int le_graphics;
#define le_graphics_name "SDL Graphics"
static int le_input;
#define le_input_name "SDL Input"
static int le_container;
#define le_container_name "SDL Container"
static int le_label;
#define le_label_name "SDL Label"
static int le_button;
#define le_button_name "SDL Button"
static int le_textbox;
#define le_textbox_name "SDL TextBox"
static int le_textfield;
#define le_textfield_name "SDL TextField"
#ifdef HAVE_SDL_SMPEG
static int le_smpeg;
#define le_smpeg_name "SDL SMPEG"
#endif
#ifdef HAVE_SDL_TTF
static int le_font;
#define le_font_name "SDL Font"
#endif
#ifdef HAVE_SDL_GFX
static int le_fpsmanager;
#define le_fpsmanager_name "SDL GFX FpsManager"
#endif
static void _guichan_cdrom(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
static void _guichan_timer(zend_rsrc_list_entry *rsrc TSRMLS_DC) {

				/* hello world */
				php_sdl_timer *t = (php_sdl_timer *)rsrc->ptr;
				zval_ptr_dtor(&(t->callback));
				efree(t);
			}
static void _guichan_surface(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
static void _guichan_pixelformat(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
static void _guichan_cursor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
static void _guichan_overlay(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
static void _guichan_joystick(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
static void _guichan_mutex(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
static void _guichan_graphics(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
static void _guichan_input(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
static void _guichan_container(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
static void _guichan_label(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
static void _guichan_button(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
static void _guichan_textbox(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
static void _guichan_textfield(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
#ifdef HAVE_SDL_SMPEG
static void _guichan_smpeg(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
#endif
#ifdef HAVE_SDL_TTF
static void _guichan_font(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
#endif
#ifdef HAVE_SDL_GFX
static void _guichan_fpsmanager(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
}
#endif

/*******************************
 * End Resources
 *******************************/


/*******************************
 * Function Definitions
 *******************************/
static function_entry php_guichan_functions[] = {
	PHP_FE(sdl_warpmouse,	NULL)
	PHP_FE(sdl_createcursor,	NULL)
	PHP_FE(sdl_freecursor,	NULL)
	PHP_FE(sdl_setcursor,	NULL)
	PHP_FE(sdl_getcursor,	NULL)
	PHP_FE(sdl_showcursor,	NULL)
	PHP_FE(sdl_gl_loadlibrary,	NULL)
	PHP_FE(sdl_gl_getprocaddress,	NULL)
	PHP_FE(sdl_gl_getattribute,	NULL)
	PHP_FE(sdl_gl_setattribute,	NULL)
	PHP_FE(sdl_gl_swapbuffers,	NULL)
	PHP_FE(sdl_createyuvoverlay,	NULL)
	PHP_FE(sdl_lockyuvoverlay,	NULL)
	PHP_FE(sdl_unlockyuvoverlay,	NULL)
	PHP_FE(sdl_displayyuvoverlay,	NULL)
	PHP_FE(sdl_freeyuvoverlay,	NULL)
	PHP_FE(sdl_wm_setcaption,	NULL)
	PHP_FE(sdl_wm_getcaption,	NULL)
	PHP_FE(sdl_wm_seticon,	NULL)
	PHP_FE(sdl_wm_iconifywindow,	NULL)
	PHP_FE(sdl_wm_togglefullscreen,	NULL)
	PHP_FE(sdl_wm_grabinput,	NULL)
	PHP_FE(sdl_button,	NULL)
	PHP_FE(sdl_pumpevents,	NULL)
	PHP_FE(sdl_pollevent,	NULL)
	PHP_FE(sdl_waitevent,	NULL)
	PHP_FE(sdl_peepevents,	NULL)
	PHP_FE(sdl_pushevent,	NULL)
	PHP_FE(sdl_seteventfilter,	NULL)
	PHP_FE(sdl_geteventfilter,	NULL)
	PHP_FE(sdl_eventstate,	NULL)
	PHP_FE(sdl_getkeystate,	NULL)
	PHP_FE(sdl_getmodstate,	NULL)
	PHP_FE(sdl_setmodstate,	NULL)
	PHP_FE(sdl_getkeyname,	NULL)
	PHP_FE(sdl_enableunicode,	NULL)
	PHP_FE(sdl_enablekeyrepeat,	NULL)
	PHP_FE(sdl_getmousestate,	NULL)
	PHP_FE(sdl_getrelativemousestate,	NULL)
	PHP_FE(sdl_getappstate,	NULL)
	PHP_FE(sdl_numjoysticks,	NULL)
	PHP_FE(sdl_joystickname,	NULL)
	PHP_FE(sdl_joystickopen,	NULL)
	PHP_FE(sdl_joystickopened,	NULL)
	PHP_FE(sdl_joystickindex,	NULL)
	PHP_FE(sdl_joysticknumaxes,	NULL)
	PHP_FE(sdl_joysticknumballs,	NULL)
	PHP_FE(sdl_joysticknumhats,	NULL)
	PHP_FE(sdl_joysticknumbuttons,	NULL)
	PHP_FE(sdl_joystickupdate,	NULL)
	PHP_FE(sdl_joystickeventstate,	NULL)
	PHP_FE(sdl_joystickgetaxis,	NULL)
	PHP_FE(sdl_joystickgethat,	NULL)
	PHP_FE(sdl_joystickgetball,	NULL)
	PHP_FE(sdl_joystickgetbutton,	NULL)
	PHP_FE(sdl_joystickclose,	NULL)
	PHP_FE(sdl_cd_indrive,	NULL)
	PHP_FE(sdl_frames_to_msf,	NULL)
	PHP_FE(sdl_msf_to_frames,	NULL)
	PHP_FE(sdl_cdnumdrives,	NULL)
	PHP_FE(sdl_cdname,	NULL)
	PHP_FE(sdl_cdopen,	NULL)
	PHP_FE(sdl_cdstatus,	NULL)
	PHP_FE(sdl_cdplay,	NULL)
	PHP_FE(sdl_cdplaytracks,	NULL)
	PHP_FE(sdl_cdpause,	NULL)
	PHP_FE(sdl_cdresume,	NULL)
	PHP_FE(sdl_cdstop,	NULL)
	PHP_FE(sdl_cdeject,	NULL)
	PHP_FE(sdl_cdclose,	NULL)
	PHP_FE(sdl_createmutex,	NULL)
	PHP_FE(sdl_destroymutex,	NULL)
	PHP_FE(sdl_mutexp,	NULL)
	PHP_FE(sdl_mutexv,	NULL)
	PHP_FE(sdl_getticks,	NULL)
	PHP_FE(sdl_delay,	NULL)
	PHP_FE(sdl_addtimer,	NULL)
	PHP_FE(sdl_removetimer,	NULL)
	PHP_FE(sdl_init,	NULL)
	PHP_FE(sdl_initsubsystem,	NULL)
	PHP_FE(sdl_quitsubsystem,	NULL)
	PHP_FE(sdl_wasinit,	NULL)
	PHP_FE(sdl_quit,	NULL)
	PHP_FE(sdl_geterror,	NULL)
	PHP_FE(sdl_mustlock,	NULL)
	PHP_FE(sdl_getvideosurface,	NULL)
	PHP_FE(sdl_getvideoinfo,	NULL)
	PHP_FE(sdl_videodrivername,	NULL)
	PHP_FE(sdl_listmodes,	NULL)
	PHP_FE(sdl_videomodeok,	NULL)
	PHP_FE(sdl_setvideomode,	NULL)
	PHP_FE(sdl_updaterect,	NULL)
	PHP_FE(sdl_updaterects,	NULL)
	PHP_FE(sdl_flip,	NULL)
	PHP_FE(sdl_setcolors,	NULL)
	PHP_FE(sdl_setpalette,	NULL)
	PHP_FE(sdl_setgamma,	NULL)
	PHP_FE(sdl_getgammaramp,	NULL)
	PHP_FE(sdl_setgammaramp,	NULL)
	PHP_FE(sdl_maprgb,	NULL)
	PHP_FE(sdl_maprgba,	NULL)
	PHP_FE(sdl_getrgb,	NULL)
	PHP_FE(sdl_getrgba,	NULL)
	PHP_FE(sdl_creatergbsurface,	NULL)
	PHP_FE(sdl_creatergbsurfacefrom,	NULL)
	PHP_FE(sdl_freesurface,	NULL)
	PHP_FE(sdl_locksurface,	NULL)
	PHP_FE(sdl_unlocksurface,	NULL)
	PHP_FE(sdl_loadbmp,	NULL)
	PHP_FE(sdl_savebmp,	NULL)
	PHP_FE(sdl_setcolorkey,	NULL)
	PHP_FE(sdl_setalpha,	NULL)
	PHP_FE(sdl_setcliprect,	NULL)
	PHP_FE(sdl_getcliprect,	NULL)
	PHP_FE(sdl_convertsurface,	NULL)
	PHP_FE(sdl_blitsurface,	NULL)
	PHP_FE(sdl_fillrect,	NULL)
	PHP_FE(sdl_displayformat,	NULL)
	PHP_FE(sdl_displayformatalpha,	NULL)
	PHP_FE(guichan_init,	NULL)
	PHP_FE(guichan_newgraphics,	NULL)
	PHP_FE(guichan_setgraphics,	NULL)
	PHP_FE(guichan_newinput,	NULL)
	PHP_FE(guichan_pushinput,	NULL)
	PHP_FE(guichan_newcontainer,	NULL)
	PHP_FE(guichan_newimagefont,	NULL)
	PHP_FE(guichan_setglobalfont,	NULL)
	PHP_FE(guichan_newlabel,	NULL)
	PHP_FE(guichan_newbutton,	NULL)
	PHP_FE(guichan_newtextbox,	NULL)
	PHP_FE(guichan_newtextfield,	NULL)
	PHP_FE(guichan_logic,	NULL)
	PHP_FE(guichan_draw,	NULL)
	PHP_FE(guichan_quit,	NULL)
	PHP_FE(guichan_test,	NULL)
/* condition */
#ifdef HAVE_SDL_IMAGE
	PHP_FE(img_load,	NULL)
#endif
/* end condition */
/* condition */
#ifdef HAVE_SDL_GFX
	PHP_FE(sdlgfx_pixelColor,	NULL)
	PHP_FE(sdlgfx_pixelRGBA,	NULL)
	PHP_FE(sdlgfx_hlineColor,	NULL)
	PHP_FE(sdlgfx_hlineRGBA,	NULL)
	PHP_FE(sdlgfx_vlineColor,	NULL)
	PHP_FE(sdlgfx_vlineRGBA,	NULL)
	PHP_FE(sdlgfx_rectangleColor,	NULL)
	PHP_FE(sdlgfx_rectangleRGBA,	NULL)
	PHP_FE(sdlgfx_boxColor,	NULL)
	PHP_FE(sdlgfx_boxRGBA,	NULL)
	PHP_FE(sdlgfx_lineColor,	NULL)
	PHP_FE(sdlgfx_lineRGBA,	NULL)
	PHP_FE(sdlgfx_aalineColor,	NULL)
	PHP_FE(sdlgfx_aalineRGBA,	NULL)
	PHP_FE(sdlgfx_circleColor,	NULL)
	PHP_FE(sdlgfx_circleRGBA,	NULL)
	PHP_FE(sdlgfx_aacircleColor,	NULL)
	PHP_FE(sdlgfx_aacircleRGBA,	NULL)
	PHP_FE(sdlgfx_filledCircleColor,	NULL)
	PHP_FE(sdlgfx_filledCircleRGBA,	NULL)
	PHP_FE(sdlgfx_ellipseColor,	NULL)
	PHP_FE(sdlgfx_ellipseRGBA,	NULL)
	PHP_FE(sdlgfx_aaellipseColor,	NULL)
	PHP_FE(sdlgfx_aaellipseRGBA,	NULL)
	PHP_FE(sdlgfx_filledEllipseColor,	NULL)
	PHP_FE(sdlgfx_filledEllipseRGBA,	NULL)
	PHP_FE(sdlgfx_pieColor,	NULL)
	PHP_FE(sdlgfx_pieRGBA,	NULL)
	PHP_FE(sdlgfx_filledPieColor,	NULL)
	PHP_FE(sdlgfx_filledPieRGBA,	NULL)
	PHP_FE(sdlgfx_trigonColor,	NULL)
	PHP_FE(sdlgfx_trigonRGBA,	NULL)
	PHP_FE(sdlgfx_aatrigonColor,	NULL)
	PHP_FE(sdlgfx_aatrigonRGBA,	NULL)
	PHP_FE(sdlgfx_filledTrigonColor,	NULL)
	PHP_FE(sdlgfx_filledTrigonRGBA,	NULL)
	PHP_FE(sdlgfx_polygonColor,	NULL)
	PHP_FE(sdlgfx_polygonRGBA,	NULL)
	PHP_FE(sdlgfx_aapolygonColor,	NULL)
	PHP_FE(sdlgfx_aapolygonRGBA,	NULL)
	PHP_FE(sdlgfx_filledPolygonColor,	NULL)
	PHP_FE(sdlgfx_filledPolygonRGBA,	NULL)
	PHP_FE(sdlgfx_bezierColor,	NULL)
	PHP_FE(sdlgfx_bezierRGBA,	NULL)
	PHP_FE(sdlgfx_characterColor,	NULL)
	PHP_FE(sdlgfx_characterRGBA,	NULL)
	PHP_FE(sdlgfx_stringColor,	NULL)
	PHP_FE(sdlgfx_stringRGBA,	NULL)
	PHP_FE(sdlgfx_gfxPrimitivesSetFont,	NULL)
	PHP_FE(sdlgfx_rotozoomSurface,	NULL)
	PHP_FE(sdlgfx_rotozoomSurfaceXY,	NULL)
	PHP_FE(sdlgfx_zoomSurface,	NULL)
	PHP_FE(sdlgfx_initFramerate,	NULL)
	PHP_FE(sdlgfx_setFramerate,	NULL)
	PHP_FE(sdlgfx_getFramerate,	NULL)
	PHP_FE(sdlgfx_framerateDelay,	NULL)
#endif
/* end condition */
/* condition */
#ifdef HAVE_SDL_TTF
	PHP_FE(sdlttf_Init,	NULL)
	PHP_FE(sdlttf_Quit,	NULL)
	PHP_FE(sdlttf_WasInit,	NULL)
	PHP_FE(sdlttf_OpenFont,	NULL)
	PHP_FE(sdlttf_OpenFontIndex,	NULL)
	PHP_FE(sdlttf_OpenFontRW,	NULL)
	PHP_FE(sdlttf_OpenFontIndexRW,	NULL)
	PHP_FE(sdlttf_GetFontStyle,	NULL)
	PHP_FE(sdlttf_SetFontStyle,	NULL)
	PHP_FE(sdlttf_FontHeight,	NULL)
	PHP_FE(sdlttf_FontAscent,	NULL)
	PHP_FE(sdlttf_FontDescent,	NULL)
	PHP_FE(sdlttf_FontLineSkip,	NULL)
	PHP_FE(sdlttf_FontFaces,	NULL)
	PHP_FE(sdlttf_FontFaceIsFixedWidth,	NULL)
	PHP_FE(sdlttf_FontFaceFamilyName,	NULL)
	PHP_FE(sdlttf_FontFaceStyleName,	NULL)
	PHP_FE(sdlttf_GlyphMetrics,	NULL)
	PHP_FE(sdlttf_SizeText,	NULL)
	PHP_FE(sdlttf_SizeUTF8,	NULL)
	PHP_FE(sdlttf_SizeUNICODE,	NULL)
	PHP_FE(sdlttf_RenderText_Solid,	NULL)
	PHP_FE(sdlttf_RenderUTF8_Solid,	NULL)
	PHP_FE(sdlttf_RenderUNICODE_Solid,	NULL)
	PHP_FE(sdlttf_RenderGlyph_Solid,	NULL)
	PHP_FE(sdlttf_RenderText_Shaded,	NULL)
	PHP_FE(sdlttf_RenderUTF8_Shaded,	NULL)
	PHP_FE(sdlttf_RenderUNICODE_Shaded,	NULL)
	PHP_FE(sdlttf_RenderGlyph_Shaded,	NULL)
	PHP_FE(sdlttf_RenderText_Blended,	NULL)
	PHP_FE(sdlttf_RenderUTF8_Blended,	NULL)
	PHP_FE(sdlttf_RenderUNICODE_Blended,	NULL)
	PHP_FE(sdlttf_RenderGlyph_Blended,	NULL)
	PHP_FE(sdlttf_CloseFont,	NULL)
#endif
/* end condition */
	{ NULL, NULL, NULL }
};

/*******************************
 * End Function Definitions
 *******************************/

static zend_module_dep module_deps[] = {
	//ZEND_MOD_REQUIRED("sdl")
	{NULL, NULL, NULL}
};

/*******************************
 * Standard Module Entry
 *******************************/
zend_module_entry guichan_module_entry = {
	STANDARD_MODULE_HEADER_EX,
	NULL,
	module_deps,
	PHP_GUICHAN_EXTNAME,
	php_guichan_functions, /* Functions */
	PHP_MINIT(guichan), /* MINIT */
	PHP_MSHUTDOWN(guichan), /* MSHUTDOWN */
	PHP_RINIT(guichan), /* RINIT */
	PHP_RSHUTDOWN(guichan), /* RSHUTDOWN */
	PHP_MINFO(guichan), /* MINFO */
	PHP_GUICHAN_EXTVER,
	STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_GUICHAN
//extern "C"
//{
ZEND_GET_MODULE(guichan)
//}
#endif
/*******************************
 * End Standard Module Entry
 *******************************/

/*******************************
 * Init Globals
 *******************************/
/* getting from php_guichan_globals.c */
static void php_guichan_init_globals(zend_guichan_globals *guichan_globals) {
	guichan_globals->show_sdl_errors=1;
}


static void guichan_mshutdown(void) {
}

/* end getting from php_guichan_globals.c*/

/*******************************
 * End Init Globals
 *******************************/

/*******************************
 * PHP *_FUNCTIONS
 *******************************/
PHP_MINIT_FUNCTION(guichan) {
	ZEND_INIT_MODULE_GLOBALS(guichan,php_guichan_init_globals,NULL);
	le_cdrom=zend_register_list_destructors_ex(_guichan_cdrom,NULL,le_cdrom_name, module_number);
	le_timer=zend_register_list_destructors_ex(_guichan_timer,NULL,le_timer_name, module_number);
	le_surface=zend_register_list_destructors_ex(_guichan_surface,NULL,le_surface_name, module_number);
	le_pixelformat=zend_register_list_destructors_ex(_guichan_pixelformat,NULL,le_pixelformat_name, module_number);
	le_cursor=zend_register_list_destructors_ex(_guichan_cursor,NULL,le_cursor_name, module_number);
	le_overlay=zend_register_list_destructors_ex(_guichan_overlay,NULL,le_overlay_name, module_number);
	le_joystick=zend_register_list_destructors_ex(_guichan_joystick,NULL,le_joystick_name, module_number);
	le_mutex=zend_register_list_destructors_ex(_guichan_mutex,NULL,le_mutex_name, module_number);
	le_graphics=zend_register_list_destructors_ex(_guichan_graphics,NULL,le_graphics_name, module_number);
	le_input=zend_register_list_destructors_ex(_guichan_input,NULL,le_input_name, module_number);
	le_container=zend_register_list_destructors_ex(_guichan_container,NULL,le_container_name, module_number);
	le_label=zend_register_list_destructors_ex(_guichan_label,NULL,le_label_name, module_number);
	le_button=zend_register_list_destructors_ex(_guichan_button,NULL,le_button_name, module_number);
	le_textbox=zend_register_list_destructors_ex(_guichan_textbox,NULL,le_textbox_name, module_number);
	le_textfield=zend_register_list_destructors_ex(_guichan_textfield,NULL,le_textfield_name, module_number);
#ifdef HAVE_SDL_SMPEG
	le_smpeg=zend_register_list_destructors_ex(_guichan_smpeg,NULL,le_smpeg_name, module_number);
#endif
#ifdef HAVE_SDL_TTF
	le_font=zend_register_list_destructors_ex(_guichan_font,NULL,le_font_name, module_number);
#endif
#ifdef HAVE_SDL_GFX
	le_fpsmanager=zend_register_list_destructors_ex(_guichan_fpsmanager,NULL,le_fpsmanager_name, module_number);
#endif

	REGISTER_LONG_CONSTANT("SDL_INIT_TIMER",SDL_INIT_TIMER,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_INIT_AUDIO",SDL_INIT_AUDIO,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_INIT_VIDEO",SDL_INIT_VIDEO,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_INIT_CDROM",SDL_INIT_CDROM,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_INIT_JOYSTICK",SDL_INIT_JOYSTICK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_INIT_NOPARACHUTE",SDL_INIT_NOPARACHUTE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_INIT_EVENTTHREAD",SDL_INIT_EVENTTHREAD,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_INIT_EVERYTHING",SDL_INIT_EVERYTHING,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_CD_TRAYEMPTY", CD_TRAYEMPTY,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_CD_STOPPED", CD_STOPPED,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_CD_PLAYING", CD_PLAYING,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_CD_PAUSED", CD_PAUSED,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_CD_ERROR", CD_ERROR,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_AUDIO_TRACK", SDL_AUDIO_TRACK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_DATA_TRACK", SDL_DATA_TRACK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_CD_FPS", CD_FPS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_MAX_TRACKS",SDL_MAX_TRACKS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_SWSURFACE",SDL_SWSURFACE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_HWSURFACE",SDL_HWSURFACE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_ASYNCBLIT",SDL_ASYNCBLIT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_ANYFORMAT",SDL_ANYFORMAT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_HWPALETTE",SDL_HWPALETTE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_DOUBLEBUF",SDL_DOUBLEBUF,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_FULLSCREEN",SDL_FULLSCREEN,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_OPENGL",SDL_OPENGL,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_OPENGLBLIT",SDL_OPENGLBLIT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_RESIZABLE",SDL_RESIZABLE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_NOFRAME",SDL_NOFRAME,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_HWACCEL",SDL_HWACCEL,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_SRCCOLORKEY",SDL_SRCCOLORKEY,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_RLEACCELOK",SDL_HWACCEL,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_RLEACCEL",SDL_RLEACCEL,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_SRCALPHA",SDL_SRCALPHA,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_PREALLOC",SDL_SRCALPHA,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GL_RED_SIZE",SDL_GL_RED_SIZE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GL_GREEN_SIZE",SDL_GL_GREEN_SIZE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GL_BLUE_SIZE",SDL_GL_BLUE_SIZE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GL_ALPHA_SIZE",SDL_GL_ALPHA_SIZE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GL_BUFFER_SIZE",SDL_GL_BUFFER_SIZE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GL_DOUBLEBUFFER",SDL_GL_DOUBLEBUFFER,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GL_DEPTH_SIZE",SDL_GL_DEPTH_SIZE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GL_STENCIL_SIZE",SDL_GL_STENCIL_SIZE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GL_ACCUM_RED_SIZE",SDL_GL_ACCUM_RED_SIZE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GL_ACCUM_GREEN_SIZE",SDL_GL_ACCUM_GREEN_SIZE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GL_ACCUM_BLUE_SIZE",SDL_GL_ACCUM_BLUE_SIZE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GL_ACCUM_ALPHA_SIZE",SDL_GL_ACCUM_ALPHA_SIZE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_YV12_OVERLAY",SDL_YV12_OVERLAY,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_IYUV_OVERLAY",SDL_IYUV_OVERLAY,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_YUY2_OVERLAY",SDL_YUY2_OVERLAY,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_UYVY_OVERLAY",SDL_UYVY_OVERLAY,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_YVYU_OVERLAY",SDL_YVYU_OVERLAY,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GRAB_QUERY",SDL_GRAB_QUERY,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GRAB_OFF",SDL_GRAB_OFF,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GRAB_ON",SDL_GRAB_ON,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_PRESSED",SDL_PRESSED,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_RELEASED",SDL_RELEASED,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_QUERY",SDL_QUERY,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_IGNORE",SDL_IGNORE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_DISABLE",SDL_DISABLE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_ENABLE",SDL_ENABLE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_ADDEVENT",SDL_ADDEVENT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_PEEKEVENT",SDL_PEEKEVENT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_GETEVENT",SDL_GETEVENT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_ALLEVENTS",SDL_ALLEVENTS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_ACTIVEEVENTMASK",SDL_ACTIVEEVENTMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_KEYDOWNMASK",SDL_KEYDOWNMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_KEYUPMASK",SDL_KEYUPMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_MOUSEMOTIONMASK",SDL_MOUSEMOTIONMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_MOUSEBUTTONDOWNMASK",SDL_MOUSEBUTTONDOWNMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_MOUSEBUTTONUPMASK",SDL_MOUSEBUTTONUPMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_MOUSEEVENTMASK",SDL_MOUSEEVENTMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_JOYAXISMOTIONMASK",SDL_JOYAXISMOTIONMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_JOYBALLMOTIONMASK",SDL_JOYBALLMOTIONMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_JOYHATMOTIONMASK",SDL_JOYHATMOTIONMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_JOYBUTTONDOWNMASK",SDL_JOYBUTTONDOWNMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_JOYBUTTONUPMASK",SDL_JOYBUTTONUPMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_JOYEVENTMASK",SDL_JOYEVENTMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_VIDEORESIZEMASK",SDL_VIDEORESIZEMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_VIDEOEXPOSEMASK",SDL_VIDEOEXPOSEMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_QUITMASK",SDL_QUITMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_SYSWMEVENTMASK",SDL_SYSWMEVENTMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_NOEVENT",SDL_NOEVENT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_ACTIVEEVENT",SDL_ACTIVEEVENT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_KEYDOWN",SDL_KEYDOWN,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_KEYUP",SDL_KEYUP,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_MOUSEMOTION",SDL_MOUSEMOTION,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_MOUSEBUTTONDOWN",SDL_MOUSEBUTTONDOWN,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_MOUSEBUTTONUP",SDL_MOUSEBUTTONUP,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_JOYAXISMOTION",SDL_JOYAXISMOTION,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_JOYBALLMOTION",SDL_JOYBALLMOTION,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_JOYHATMOTION",SDL_JOYHATMOTION,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_JOYBUTTONDOWN",SDL_JOYBUTTONDOWN,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_JOYBUTTONUP",SDL_JOYBUTTONUP,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_QUIT",SDL_QUIT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_SYSWMEVENT",SDL_SYSWMEVENT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_EVENT_RESERVEDA",SDL_EVENT_RESERVEDA,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_EVENT_RESERVEDB",SDL_EVENT_RESERVEDB,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_VIDEORESIZE",SDL_VIDEORESIZE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_VIDEOEXPOSE",SDL_VIDEOEXPOSE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_EVENT_RESERVED2",SDL_EVENT_RESERVED2,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_EVENT_RESERVED3",SDL_EVENT_RESERVED3,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_EVENT_RESERVED4",SDL_EVENT_RESERVED4,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_EVENT_RESERVED5",SDL_EVENT_RESERVED5,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_EVENT_RESERVED6",SDL_EVENT_RESERVED6,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_EVENT_RESERVED7",SDL_EVENT_RESERVED7,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_USEREVENT",SDL_USEREVENT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_NUMEVENTS",SDL_NUMEVENTS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_APPMOUSEFOCUS",SDL_APPMOUSEFOCUS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_APPINPUTFOCUS",SDL_APPINPUTFOCUS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_APPACTIVE",SDL_APPACTIVE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_UNKNOWN",SDLK_UNKNOWN,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_FIRST",SDLK_FIRST,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_BACKSPACE",SDLK_BACKSPACE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_TAB",SDLK_TAB,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_CLEAR",SDLK_CLEAR,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_RETURN",SDLK_RETURN,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_PAUSE",SDLK_PAUSE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_ESCAPE",SDLK_ESCAPE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_SPACE",SDLK_SPACE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_EXCLAIM",SDLK_EXCLAIM,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_QUOTEDBL",SDLK_QUOTEDBL,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_HASH",SDLK_HASH,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_DOLLAR",SDLK_DOLLAR,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_AMPERSAND",SDLK_AMPERSAND,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_QUOTE",SDLK_QUOTE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_LEFTPAREN",SDLK_LEFTPAREN,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_RIGHTPAREN",SDLK_RIGHTPAREN,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_ASTERISK",SDLK_ASTERISK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_PLUS",SDLK_PLUS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_COMMA",SDLK_COMMA,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_MINUS",SDLK_MINUS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_PERIOD",SDLK_PERIOD,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_SLASH",SDLK_SLASH,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_0",SDLK_0,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_1",SDLK_1,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_2",SDLK_2,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_3",SDLK_3,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_4",SDLK_4,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_5",SDLK_5,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_6",SDLK_6,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_7",SDLK_7,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_8",SDLK_8,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_9",SDLK_9,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_COLON",SDLK_COLON,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_SEMICOLON",SDLK_SEMICOLON,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_LESS",SDLK_LESS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_EQUALS",SDLK_EQUALS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_GREATER",SDLK_GREATER,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_QUESTION",SDLK_QUESTION,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_AT",SDLK_AT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_LEFTBRACKET",SDLK_LEFTBRACKET,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_BACKSLASH",SDLK_BACKSLASH,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_RIGHTBRACKET",SDLK_RIGHTBRACKET,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_CARET",SDLK_CARET,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_UNDERSCORE",SDLK_UNDERSCORE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_BACKQUOTE",SDLK_BACKQUOTE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_a",SDLK_a,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_b",SDLK_b,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_c",SDLK_c,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_d",SDLK_d,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_e",SDLK_e,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_f",SDLK_f,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_g",SDLK_g,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_h",SDLK_h,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_i",SDLK_i,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_j",SDLK_j,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_k",SDLK_k,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_l",SDLK_l,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_m",SDLK_m,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_n",SDLK_n,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_o",SDLK_o,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_p",SDLK_p,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_q",SDLK_q,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_r",SDLK_r,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_s",SDLK_s,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_t",SDLK_t,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_u",SDLK_u,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_v",SDLK_v,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_w",SDLK_w,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_x",SDLK_x,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_y",SDLK_y,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_z",SDLK_z,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_DELETE",SDLK_DELETE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_0",SDLK_WORLD_0,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_1",SDLK_WORLD_1,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_2",SDLK_WORLD_2,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_3",SDLK_WORLD_3,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_4",SDLK_WORLD_4,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_5",SDLK_WORLD_5,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_6",SDLK_WORLD_6,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_7",SDLK_WORLD_7,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_8",SDLK_WORLD_8,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_9",SDLK_WORLD_9,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_10",SDLK_WORLD_10,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_11",SDLK_WORLD_11,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_12",SDLK_WORLD_12,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_13",SDLK_WORLD_13,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_14",SDLK_WORLD_14,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_15",SDLK_WORLD_15,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_16",SDLK_WORLD_16,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_17",SDLK_WORLD_17,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_18",SDLK_WORLD_18,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_19",SDLK_WORLD_19,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_20",SDLK_WORLD_20,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_21",SDLK_WORLD_21,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_22",SDLK_WORLD_22,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_23",SDLK_WORLD_23,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_24",SDLK_WORLD_24,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_25",SDLK_WORLD_25,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_26",SDLK_WORLD_26,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_27",SDLK_WORLD_27,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_28",SDLK_WORLD_28,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_29",SDLK_WORLD_29,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_30",SDLK_WORLD_30,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_31",SDLK_WORLD_31,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_32",SDLK_WORLD_32,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_33",SDLK_WORLD_33,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_34",SDLK_WORLD_34,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_35",SDLK_WORLD_35,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_36",SDLK_WORLD_36,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_37",SDLK_WORLD_37,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_38",SDLK_WORLD_38,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_39",SDLK_WORLD_39,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_40",SDLK_WORLD_40,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_41",SDLK_WORLD_41,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_42",SDLK_WORLD_42,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_43",SDLK_WORLD_43,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_44",SDLK_WORLD_44,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_45",SDLK_WORLD_45,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_46",SDLK_WORLD_46,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_47",SDLK_WORLD_47,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_48",SDLK_WORLD_48,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_49",SDLK_WORLD_49,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_50",SDLK_WORLD_50,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_51",SDLK_WORLD_51,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_52",SDLK_WORLD_52,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_53",SDLK_WORLD_53,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_54",SDLK_WORLD_54,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_55",SDLK_WORLD_55,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_56",SDLK_WORLD_56,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_57",SDLK_WORLD_57,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_58",SDLK_WORLD_58,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_59",SDLK_WORLD_59,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_60",SDLK_WORLD_60,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_61",SDLK_WORLD_61,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_62",SDLK_WORLD_62,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_63",SDLK_WORLD_63,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_64",SDLK_WORLD_64,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_65",SDLK_WORLD_65,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_66",SDLK_WORLD_66,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_67",SDLK_WORLD_67,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_68",SDLK_WORLD_68,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_69",SDLK_WORLD_69,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_70",SDLK_WORLD_70,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_71",SDLK_WORLD_71,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_72",SDLK_WORLD_72,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_73",SDLK_WORLD_73,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_74",SDLK_WORLD_74,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_75",SDLK_WORLD_75,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_76",SDLK_WORLD_76,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_77",SDLK_WORLD_77,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_78",SDLK_WORLD_78,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_79",SDLK_WORLD_79,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_80",SDLK_WORLD_80,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_81",SDLK_WORLD_81,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_82",SDLK_WORLD_82,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_83",SDLK_WORLD_83,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_84",SDLK_WORLD_84,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_85",SDLK_WORLD_85,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_86",SDLK_WORLD_86,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_87",SDLK_WORLD_87,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_88",SDLK_WORLD_88,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_89",SDLK_WORLD_89,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_90",SDLK_WORLD_90,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_91",SDLK_WORLD_91,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_92",SDLK_WORLD_92,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_93",SDLK_WORLD_93,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_94",SDLK_WORLD_94,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_WORLD_95",SDLK_WORLD_95,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP0",SDLK_KP0,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP1",SDLK_KP1,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP2",SDLK_KP2,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP3",SDLK_KP3,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP4",SDLK_KP4,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP5",SDLK_KP5,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP6",SDLK_KP6,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP7",SDLK_KP7,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP8",SDLK_KP8,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP9",SDLK_KP9,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP_PERIOD",SDLK_KP_PERIOD,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP_DIVIDE",SDLK_KP_DIVIDE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP_MULTIPLY",SDLK_KP_MULTIPLY,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP_MINUS",SDLK_KP_MINUS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP_PLUS",SDLK_KP_PLUS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP_ENTER",SDLK_KP_ENTER,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_KP_EQUALS",SDLK_KP_EQUALS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_UP",SDLK_UP,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_DOWN",SDLK_DOWN,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_RIGHT",SDLK_RIGHT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_LEFT",SDLK_LEFT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_INSERT",SDLK_INSERT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_HOME",SDLK_HOME,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_END",SDLK_END,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_PAGEUP",SDLK_PAGEUP,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_PAGEDOWN",SDLK_PAGEDOWN,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F1",SDLK_F1,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F2",SDLK_F2,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F3",SDLK_F3,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F4",SDLK_F4,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F5",SDLK_F5,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F6",SDLK_F6,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F7",SDLK_F7,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F8",SDLK_F8,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F9",SDLK_F9,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F10",SDLK_F10,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F11",SDLK_F11,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F12",SDLK_F12,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F13",SDLK_F13,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F14",SDLK_F14,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_F15",SDLK_F15,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_NUMLOCK",SDLK_NUMLOCK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_CAPSLOCK",SDLK_CAPSLOCK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_SCROLLOCK",SDLK_SCROLLOCK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_RSHIFT",SDLK_RSHIFT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_LSHIFT",SDLK_LSHIFT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_RCTRL",SDLK_RCTRL,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_LCTRL",SDLK_LCTRL,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_RALT",SDLK_RALT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_LALT",SDLK_LALT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_RMETA",SDLK_RMETA,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_LMETA",SDLK_LMETA,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_LSUPER",SDLK_LSUPER,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_RSUPER",SDLK_RSUPER,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_MODE",SDLK_MODE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_COMPOSE",SDLK_COMPOSE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_HELP",SDLK_HELP,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_PRINT",SDLK_PRINT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_SYSREQ",SDLK_SYSREQ,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_BREAK",SDLK_BREAK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_MENU",SDLK_MENU,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_POWER",SDLK_POWER,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_EURO",SDLK_EURO,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDLK_LAST",SDLK_LAST,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_NONE",KMOD_NONE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_LSHIFT",KMOD_LSHIFT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_RSHIFT",KMOD_RSHIFT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_LCTRL",KMOD_LCTRL,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_RCTRL",KMOD_RCTRL,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_LALT",KMOD_LALT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_RALT",KMOD_RALT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_LMETA",KMOD_LMETA,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_RMETA",KMOD_RMETA,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_NUM",KMOD_NUM,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_CAPS",KMOD_CAPS,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_MODE",KMOD_MODE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_RESERVED",KMOD_RESERVED,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_CTRL",KMOD_CTRL,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_SHIFT",KMOD_SHIFT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_ALT",KMOD_ALT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("KMOD_META",KMOD_META,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_BUTTON_LEFT",SDL_BUTTON_LEFT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_BUTTON_MIDDLE",SDL_BUTTON_MIDDLE,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_BUTTON_RIGHT",SDL_BUTTON_RIGHT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_BUTTON_LMASK",SDL_BUTTON_LMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_BUTTON_MMASK",SDL_BUTTON_MMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_BUTTON_RMASK",SDL_BUTTON_RMASK,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_HAT_CENTERED",SDL_HAT_CENTERED,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_HAT_UP",SDL_HAT_UP,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_HAT_RIGHT",SDL_HAT_RIGHT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_HAT_DOWN",SDL_HAT_DOWN,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_HAT_LEFT",SDL_HAT_LEFT,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_HAT_RIGHTUP",SDL_HAT_RIGHTUP,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_HAT_RIGHTDOWN",SDL_HAT_RIGHTDOWN,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_HAT_LEFTUP",SDL_HAT_LEFTUP,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_HAT_LEFTDOWN",SDL_HAT_LEFTDOWN,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_LOGPAL",SDL_LOGPAL,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_PHYSPAL",SDL_PHYSPAL,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_DEFAULT_REPEAT_DELAY",SDL_DEFAULT_REPEAT_DELAY,CONST_CS | CONST_PERSISTENT);
	REGISTER_LONG_CONSTANT("SDL_DEFAULT_REPEAT_INTERVAL",SDL_DEFAULT_REPEAT_INTERVAL,CONST_CS | CONST_PERSISTENT);
	#ifdef HAVE_SDL_SMPEG
		REGISTER_LONG_CONSTANT("SMPEG_ERROR",SMPEG_ERROR,CONST_CS | CONST_PERSISTENT);
		REGISTER_LONG_CONSTANT("SMPEG_STOPPED",SMPEG_STOPPED,CONST_CS | CONST_PERSISTENT);
		REGISTER_LONG_CONSTANT("SMPEG_PLAYING",SMPEG_PLAYING,CONST_CS | CONST_PERSISTENT);
	#endif
	#ifdef HAVE_SDL_TTF
		REGISTER_LONG_CONSTANT("TTF_STYLE_NORMAL",0x00,CONST_CS | CONST_PERSISTENT);
		REGISTER_LONG_CONSTANT("TTF_STYLE_BOLD",0x01,CONST_CS | CONST_PERSISTENT);
		REGISTER_LONG_CONSTANT("TTF_STYLE_ITALIC",0x02,CONST_CS | CONST_PERSISTENT);
		REGISTER_LONG_CONSTANT("TTF_STYLE_UNDERLINE",0x04,CONST_CS | CONST_PERSISTENT);
	#endif

	return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(guichan) {
	guichan_mshutdown();
	return SUCCESS;
}
PHP_RINIT_FUNCTION(guichan) {
	return SUCCESS;
}
PHP_RSHUTDOWN_FUNCTION(guichan) {
	return SUCCESS;
}
PHP_MINFO_FUNCTION(guichan) {
	php_info_print_table_start();
	php_info_print_table_header(2, "guichan support", "enabled");
	php_info_print_table_end();
}
/*******************************
 * End PHP *_FUNCTIONS
 *******************************/

/*******************************
 * Stuff/Conversion Code
 *******************************/
/* getting from php_guichan_stuff.c */
//#define TRUE (0==0)
//#define FALSE (!TRUE)

// finding a element by index from an array.
static int getArrayValueByIndex(zval array, long index, zval **dest) {
	zval **dest1;
	TSRMLS_FETCH();

	if (Z_TYPE(array)!=IS_ARRAY) return FALSE;
	if (zend_hash_index_find(Z_ARRVAL(array),index, (void **)&dest1)==FAILURE) {
		php_error(E_WARNING, "%s() unable to find %d in array",
					get_active_function_name(TSRMLS_C),index);
		return FALSE;
	}
	*dest=*dest1;
	return TRUE;
}

// finding a element by string key from an array.
static int getArrayValueByString(zval array, char *key, zval **dest) {
	long key_length=0;
	zval **dest1;
	TSRMLS_FETCH();

	if (Z_TYPE(array)!=IS_ARRAY) return FALSE;
	key_length=strlen(key);
	if (key && zend_hash_find(Z_ARRVAL(array),key,key_length+1,(void **)&dest1)==FAILURE) {
		php_error(E_WARNING, "%s() unable to find %s in array",
					get_active_function_name(TSRMLS_C),key);
		return FALSE;
	}
	*dest=*dest1;
	return TRUE;
}

static void dumpaVar(zval uservar) {
    TSRMLS_FETCH();

	php_printf("Yououoo\n");
	switch (Z_TYPE(uservar)) {
		case IS_NULL:
			php_printf("NULL ");
			break;
		case IS_BOOL:
			php_printf("Boolean: %s ", Z_LVAL(uservar) ? "TRUE" : "FALSE");
			break;
		case IS_LONG:
			php_printf("Long: %ld ", Z_LVAL(uservar));
			break;
		case IS_DOUBLE:
			php_printf("Double: %f ", Z_DVAL(uservar));
			break;
		case IS_STRING:
			php_printf("String: ");
			PHPWRITE(Z_STRVAL(uservar), Z_STRLEN(uservar));
			php_printf(" ");
			break;
		case IS_RESOURCE:
			php_printf("Resource ");
			break;
		case IS_ARRAY:
			php_printf("Array ");
			break;
		case IS_OBJECT:
			php_printf("Object ");
			break;
		default:
			php_printf("Unknown ");
	}
}

// counting
static ulong getArrayCount(zval array) {
	if (Z_TYPE(array)!=IS_ARRAY) return FALSE;
	return zend_hash_next_free_element(Z_ARRVAL(array));
}

int XX(void) {
	php_printf("Hello world");
	return 1;
}
void mysdl_error(const char *msg) {
    TSRMLS_FETCH();
	if (MYGLOBALS(show_sdl_errors)) {
		php_error(E_WARNING,"function:%s, error in %s: SDL Error: %s",
			get_active_function_name(TSRMLS_C),msg,SDL_GetError());
	}
}
//SDL_Rect->Array.
static void rect2array(SDL_Rect r, zval *a)
{
	array_init(a);
	add_assoc_long(a, "x", r.x);
	add_assoc_long(a, "y", r.y);
	add_assoc_long(a, "w", r.w);
	add_assoc_long(a, "h", r.h);
}

static int array2rect(zval srcrect, SDL_Rect *r) {
	zval *handle;
	if (!getArrayValueByString(srcrect,"x",&handle)) {
		r->x=0;
	} else {
		r->x=Z_LVAL_P(handle);
	}
	if (!getArrayValueByString(srcrect,"y",&handle)) {
		r->y=0;
	} else {
		r->y=Z_LVAL_P(handle);
	}
	if (!getArrayValueByString(srcrect,"w",&handle)) {
		r->w=0;
	} else {
		r->w=Z_LVAL_P(handle);
	}
	if (!getArrayValueByString(srcrect,"h",&handle)) {
		r->h=0;
	} else {
		r->h=Z_LVAL_P(handle);
	}

    return 1;
}
//SDL_PixelFormat -> Array
static void pf2array(SDL_PixelFormat *pixelformat, zval *pixelformat_array TSRMLS_DC)
{
	zval *palette, *colors, *color;
	int handle, i;

	handle = zend_list_insert(pixelformat, le_pixelformat);

	array_init(pixelformat_array);
	add_assoc_resource(pixelformat_array, "handle", handle);
	zend_list_addref(handle);

	add_assoc_long(pixelformat_array, "BitsPerPixel", pixelformat->BitsPerPixel);
	add_assoc_long(pixelformat_array, "BytesPerPixel", pixelformat->BytesPerPixel);
	add_assoc_long(pixelformat_array, "Rmask", pixelformat->Rmask);
	add_assoc_long(pixelformat_array, "Gmask", pixelformat->Gmask);
	add_assoc_long(pixelformat_array, "Bmask", pixelformat->Bmask);
	add_assoc_long(pixelformat_array, "Amask", pixelformat->Amask);
	add_assoc_long(pixelformat_array, "Rshift", pixelformat->Rshift);
	add_assoc_long(pixelformat_array, "Gshift", pixelformat->Gshift);
	add_assoc_long(pixelformat_array, "Bshift", pixelformat->Bshift);
	add_assoc_long(pixelformat_array, "Ashift", pixelformat->Ashift);
	add_assoc_long(pixelformat_array, "Rloss", pixelformat->Rloss);
	add_assoc_long(pixelformat_array, "Gloss", pixelformat->Gloss);
	add_assoc_long(pixelformat_array, "Bloss", pixelformat->Bloss);
	add_assoc_long(pixelformat_array, "Aloss", pixelformat->Aloss);
	add_assoc_long(pixelformat_array, "colorkey", pixelformat->colorkey);
	add_assoc_long(pixelformat_array, "alpha", pixelformat->alpha);

	if (pixelformat->palette == NULL) {
		add_assoc_null(pixelformat_array, "palette");
	} else {
		MAKE_STD_ZVAL(palette);
		array_init(palette);
		MAKE_STD_ZVAL(colors);
		add_assoc_long(palette, "ncolors", pixelformat->palette->ncolors);
		array_init(colors);

		for(i=0; i < pixelformat->palette->ncolors; i++)
		{
			MAKE_STD_ZVAL(color);
			array_init(color);
			add_assoc_long(color, "r", pixelformat->palette->colors[i].r);
			add_assoc_long(color, "g", pixelformat->palette->colors[i].g);
			add_assoc_long(color, "b", pixelformat->palette->colors[i].b);
			add_next_index_zval(colors, color);
		}
		add_assoc_zval(palette, "colors", colors);
		add_assoc_zval(pixelformat_array, "palette", palette);
	}
}

// SDL_Surface -> Array
static void surf2array(SDL_Surface *surface, zval *surface_array TSRMLS_DC)
{
	zval *format, *rect;
	int handle;

	handle = zend_list_insert(surface, le_surface);

	array_init(surface_array);
	add_assoc_resource(surface_array, "handle", handle);
	zend_list_addref(handle);

	add_assoc_long(surface_array, "flags", surface->flags);
	add_assoc_long(surface_array, "w", surface->w);
	add_assoc_long(surface_array, "h", surface->h);
	add_assoc_long(surface_array, "pitch", surface->pitch);
	add_assoc_long(surface_array, "refcount", surface->refcount);

	MAKE_STD_ZVAL(format);
	pf2array(surface->format, format TSRMLS_CC);
	add_assoc_zval(surface_array, "format", format);

	MAKE_STD_ZVAL(rect);
	rect2array(surface->clip_rect, rect);
	add_assoc_zval(surface_array, "clip_rect", rect);
}

static void videoinfo2array(SDL_VideoInfo *from, zval *to TSRMLS_DC) {
	zval *fmt;
	array_init(to);

	add_assoc_long(to, "hw_available", from->hw_available);
	add_assoc_long(to, "wm_available", from->wm_available);
	add_assoc_long(to, "blit_hw", from->blit_hw);
	add_assoc_long(to, "blit_hw_CC", from->blit_hw_CC);
	add_assoc_long(to, "blit_hw_A", from->blit_hw_A);
	add_assoc_long(to, "blit_sw", from->blit_sw);
	add_assoc_long(to, "blit_sw_CC", from->blit_sw_CC);
	add_assoc_long(to, "blit_sw_A", from->blit_sw_A);
	add_assoc_long(to, "blit_fill", from->blit_fill);
	add_assoc_long(to, "video_mem", from->video_mem);

	MAKE_STD_ZVAL(fmt);
	pf2array(from->vfmt, fmt TSRMLS_CC);
	add_assoc_zval(to, "vfmt", fmt);
}

static void overlay2array(SDL_Overlay *from, zval *to TSRMLS_DC) {
	int handle;

	handle = zend_list_insert(from, le_overlay);

	array_init(to);
	add_assoc_resource(to, "handle", handle);
	zend_list_addref(handle);

	add_assoc_long(to, "format", from->format);
	add_assoc_long(to, "w", from->w);
	add_assoc_long(to, "h", from->h);
	add_assoc_long(to, "planes", from->planes);
	add_assoc_long(to, "hw_overlay", from->hw_overlay);
}

static int event2array(SDL_Event event, zval *event_array TSRMLS_DC)
{
	zval *active;
	zval *key, *keysym;
	zval *motion;
	zval *button;
	zval *jaxis;
	zval *jball;
	zval *jhat;
	zval *jbutton;
	zval *resize;
	zval *quit;
	zval *user;
	zval *syswm;

	switch (event.type) {
	case SDL_ACTIVEEVENT:
		array_init(event_array);
		add_assoc_long(event_array, "type", event.type);

		// SDL_ActiveEvent active
		MAKE_STD_ZVAL(active);
		array_init(active);
		add_assoc_long(active, "type", event.active.type);
		add_assoc_long(active, "gain", event.active.gain);
		add_assoc_long(active, "state", event.active.state);
		add_assoc_zval(event_array, "active", active);
		break;
	case SDL_KEYDOWN:
	case SDL_KEYUP:
		array_init(event_array);
		add_assoc_long(event_array, "type", event.type);

		// SDL_KeyboardEvent key
		MAKE_STD_ZVAL(key);
		array_init(key);
		add_assoc_long(key, "type", event.key.type);
		add_assoc_long(key, "state", event.key.state);
		MAKE_STD_ZVAL(keysym); // key.keysym
		array_init(keysym);
		add_assoc_long(keysym, "scancode", event.key.keysym.scancode);
		add_assoc_long(keysym, "sym", event.key.keysym.sym);
		add_assoc_long(keysym, "mod", event.key.keysym.mod);
		add_assoc_long(keysym, "unicode", event.key.keysym.unicode);
		add_assoc_zval(key, "keysym", keysym);
		add_assoc_zval(event_array, "key", key);
		break;
	case SDL_MOUSEMOTION:
		array_init(event_array);
		add_assoc_long(event_array, "type", event.type);

		// SDL_MouseMotionEvent motion
		MAKE_STD_ZVAL(motion);
		array_init(motion);
		add_assoc_long(motion, "type", event.motion.type);
		add_assoc_long(motion, "state", event.motion.state);
		add_assoc_long(motion, "x", event.motion.x);
		add_assoc_long(motion, "y", event.motion.y);
		add_assoc_long(motion, "xrel", event.motion.xrel);
		add_assoc_long(motion, "yrel", event.motion.yrel);
		add_assoc_zval(event_array, "motion", motion);
		break;
	case SDL_MOUSEBUTTONDOWN:
	case SDL_MOUSEBUTTONUP:
		array_init(event_array);
		add_assoc_long(event_array, "type", event.type);

		// SDL_MouseButtonEvent button
		MAKE_STD_ZVAL(button);
		array_init(button);
		add_assoc_long(button, "type", event.button.type);
		add_assoc_long(button, "button", event.button.button);
		add_assoc_long(button, "state", event.button.state);
		add_assoc_long(button, "x", event.button.x);
		add_assoc_long(button, "y", event.button.y);
		add_assoc_zval(event_array, "button", button);
		break;
	case SDL_JOYAXISMOTION:
		array_init(event_array);
		add_assoc_long(event_array, "type", event.type);

		// SDL_JoyAxisEvent jaxis
		MAKE_STD_ZVAL(jaxis);
		array_init(jaxis);
		add_assoc_long(jaxis, "type", event.jaxis.type);
		add_assoc_long(jaxis, "which", event.jaxis.which);
		add_assoc_long(jaxis, "axis", event.jaxis.axis);
		add_assoc_long(jaxis, "value", event.jaxis.value);
		add_assoc_zval(event_array, "jaxis", jaxis);
		break;
	case SDL_JOYBALLMOTION:
		array_init(event_array);
		add_assoc_long(event_array, "type", event.type);

		// SDL_JoyBallEvent jball
		MAKE_STD_ZVAL(jball);
		array_init(jball);
		add_assoc_long(jball, "type", event.jball.type);
		add_assoc_long(jball, "which", event.jball.which);
		add_assoc_long(jball, "ball", event.jball.ball);
		add_assoc_long(jball, "xrel", event.jball.xrel);
		add_assoc_long(jball, "yrel", event.jball.yrel);
		add_assoc_zval(event_array, "jball", jball);
		break;
	case SDL_JOYHATMOTION:
		array_init(event_array);
		add_assoc_long(event_array, "type", event.type);

		// SDL_JoyHatEvent jhat
		MAKE_STD_ZVAL(jhat);
		array_init(jhat);
		add_assoc_long(jhat, "type", event.jhat.type);
		add_assoc_long(jhat, "which", event.jhat.which);
		add_assoc_long(jhat, "hat", event.jhat.hat);
		add_assoc_long(jhat, "value", event.jhat.value);
		add_assoc_zval(event_array, "jhat", jhat);
		break;
	case SDL_JOYBUTTONDOWN:
	case SDL_JOYBUTTONUP:
		array_init(event_array);
		add_assoc_long(event_array, "type", event.type);

		// SDL_JoyButtonEvent jbutton
		MAKE_STD_ZVAL(jbutton);
		array_init(jbutton);
		add_assoc_long(jbutton, "type", event.jbutton.type);
		add_assoc_long(jbutton, "which", event.jbutton.which);
		add_assoc_long(jbutton, "button", event.jbutton.button);
		add_assoc_long(jbutton, "state", event.jbutton.state);
		add_assoc_zval(event_array, "jbutton", jbutton);
		break;
	case SDL_VIDEORESIZE:
		array_init(event_array);
		add_assoc_long(event_array, "type", event.type);

		// SDL_ResizeEvent resize
		MAKE_STD_ZVAL(resize);
		array_init(resize);
		add_assoc_long(resize, "type", event.resize.type);
		add_assoc_long(resize, "w", event.resize.w);
		add_assoc_long(resize, "h", event.resize.h);
		add_assoc_zval(event_array, "resize", resize);
		break;
	case SDL_QUIT:
		array_init(event_array);
		add_assoc_long(event_array, "type", event.type);

		// SDL_QuitEvent quit
		MAKE_STD_ZVAL(quit);
		array_init(quit);
		add_assoc_long(quit, "type", event.quit.type);
		add_assoc_zval(event_array, "quit", quit);
		break;
	case SDL_USEREVENT:
		array_init(event_array);
		add_assoc_long(event_array, "type", event.type);

		// SDL_UserEvent user
		MAKE_STD_ZVAL(user);
		array_init(user);
		add_assoc_long(user, "code", event.user.code);
		//add_assoc_zval(user, "data", event.user.data1);
		if (event.user.data1!=NULL) {
			add_assoc_zval(user, "data1", (zval *)event.user.data1);
		}

		add_assoc_zval(event_array, "user", user);
		break;
	case SDL_SYSWMEVENT:
		array_init(event_array);
		add_assoc_long(event_array, "type", event.type);

		// SDL_SywWMEvent syswm
		MAKE_STD_ZVAL(syswm);
		array_init(syswm);
		add_assoc_zval(event_array, "syswm", syswm);
		break;
	/* Silently ignore the following events as the do not have any further
	 * information. */
	case SDL_VIDEOEXPOSE:
		break;
	default:
		/*
		php_error(E_WARNING, "%s() unknown event type %d",
			  get_active_function_name(TSRMLS_C), event.type);
		*/
		return 0;
	}
	return 1;
}
static int array2event(zval from TSRMLS_DC, SDL_Event *to) {
	int type;
	zval *p,*p1,*p2,*p3,*p4,*p5,*p6,*p7,*p8;

	getArrayValueByString(from,"type",&p);
	type=Z_LVAL_P(p);
	switch(type) {
	case SDL_ACTIVEEVENT:
	    to->type=type;
	    getArrayValueByString(from,"active",&p1);
	    getArrayValueByString(*p1,"type",&p2);
		getArrayValueByString(*p1,"gain",&p3);
		getArrayValueByString(*p1,"state",&p4);
		to->active.type=Z_LVAL_P(p2);
		to->active.gain=Z_LVAL_P(p3);
		to->active.state=Z_LVAL_P(p4);
		break;

	case SDL_KEYUP:
	case SDL_KEYDOWN:
	    to->type=type;
	    getArrayValueByString(from,"key",&p1);
	    getArrayValueByString(*p1,"type",&p2);
	    getArrayValueByString(*p1,"state",&p3);
	    getArrayValueByString(*p1,"keysym",&p4);
	    to->key.type=Z_LVAL_P(p2);
	    to->key.state=Z_LVAL_P(p3);
		getArrayValueByString(*p4,"scancode",&p5);
		getArrayValueByString(*p4,"sym",&p6);
		getArrayValueByString(*p4,"mod",&p7);
		getArrayValueByString(*p4,"unicode",&p8);
		to->key.keysym.scancode=(Uint8)Z_LVAL_P(p5);
		to->key.keysym.sym=(SDLKey)Z_LVAL_P(p6);
		to->key.keysym.mod=(SDLMod)Z_LVAL_P(p7);
		to->key.keysym.unicode=(SDLMod)Z_LVAL_P(p8);
		break;

	case SDL_MOUSEMOTION:
	    to->type=type;
		getArrayValueByString(from,"motion",&p1);
		getArrayValueByString(*p1,"type",&p2);
		getArrayValueByString(*p1,"state",&p3);
		getArrayValueByString(*p1,"x",&p4);
		getArrayValueByString(*p1,"y",&p5);
		getArrayValueByString(*p1,"xrel",&p6);
		getArrayValueByString(*p1,"yrel",&p7);
		to->motion.type=Z_LVAL_P(p2);
		to->motion.state=Z_LVAL_P(p3);
		to->motion.x=(Uint16)Z_LVAL_P(p4);
		to->motion.y=(Uint16)Z_LVAL_P(p5);
		to->motion.xrel=(Sint16)Z_LVAL_P(p6);
		to->motion.yrel=(Sint16)Z_LVAL_P(p7);
		break;

	case SDL_MOUSEBUTTONUP:
	case SDL_MOUSEBUTTONDOWN:
	    to->type=type;
		getArrayValueByString(from,"button",&p1);
		getArrayValueByString(*p1,"type",&p2);
		getArrayValueByString(*p1,"button",&p3);
		getArrayValueByString(*p1,"state",&p4);
		getArrayValueByString(*p1,"x",&p5);
		getArrayValueByString(*p1,"y",&p6);
		to->button.type=Z_LVAL_P(p2);
		to->button.button=(Uint8)Z_LVAL_P(p3);
		to->button.state=(Uint8)Z_LVAL_P(p4);
		to->button.x=(Sint16)Z_LVAL_P(p5);
		to->button.y=(Sint16)Z_LVAL_P(p6);
		break;

	case SDL_JOYAXISMOTION:
	    to->type=type;
	    getArrayValueByString(from,"jaxis",&p1);
		getArrayValueByString(*p1,"type",&p2);
		getArrayValueByString(*p1,"which",&p3);
		getArrayValueByString(*p1,"axis",&p4);
		getArrayValueByString(*p1,"value",&p5);
		to->jaxis.type=Z_LVAL_P(p2);
		to->jaxis.which=(Uint8)Z_LVAL_P(p3);
		to->jaxis.axis=(Uint8)Z_LVAL_P(p4);
		to->jaxis.value=(Sint16)Z_LVAL_P(p5);
		break;

	case SDL_JOYBALLMOTION:
	    to->type=type;
		getArrayValueByString(from,"jball",&p1);
		getArrayValueByString(*p1,"type",&p2);
		getArrayValueByString(*p1,"which",&p3);
		getArrayValueByString(*p1,"ball",&p4);
		getArrayValueByString(*p1,"xrel",&p5);
		getArrayValueByString(*p1,"yrel",&p6);
		to->jball.type=Z_LVAL_P(p2);
		to->jball.which=(Uint8)Z_LVAL_P(p3);
		to->jball.ball=(Uint8)Z_LVAL_P(p4);
		to->jball.xrel=(Sint16)Z_LVAL_P(p5);
		to->jball.yrel=(Sint16)Z_LVAL_P(p6);
		break;

	case SDL_JOYHATMOTION:
	    to->type=type;
		getArrayValueByString(from,"jhat",&p1);
		getArrayValueByString(*p1,"type",&p2);
		getArrayValueByString(*p1,"which",&p3);
		getArrayValueByString(*p1,"hat",&p4);
		getArrayValueByString(*p1,"value",&p5);
		to->jhat.type=Z_LVAL_P(p2);
		to->jhat.which=(Uint8)Z_LVAL_P(p3);
		to->jhat.hat=(Uint8)Z_LVAL_P(p4);
		to->jhat.value=(Uint8)Z_LVAL_P(p5);
		break;

	case SDL_JOYBUTTONUP:
	case SDL_JOYBUTTONDOWN:
	    to->type=type;
		getArrayValueByString(from,"jbutton",&p1);
		getArrayValueByString(*p1,"type",&p2);
		getArrayValueByString(*p1,"which",&p3);
		getArrayValueByString(*p1,"button",&p4);
		getArrayValueByString(*p1,"state",&p5);
		to->jbutton.type=Z_LVAL_P(p2);
		to->jbutton.which=(Uint8)Z_LVAL_P(p3);
		to->jbutton.button=(Uint8)Z_LVAL_P(p4);
		to->jbutton.state=(Uint8)Z_LVAL_P(p5);
		break;

	case SDL_VIDEORESIZE:
	    to->type=type;
		getArrayValueByString(from,"resize",&p1);
		getArrayValueByString(*p1,"type",&p2);
		getArrayValueByString(*p1,"w",&p3);
		getArrayValueByString(*p1,"h",&p4);
		to->resize.type=Z_LVAL_P(p2);
		to->resize.w=(int)Z_LVAL_P(p3);
		to->resize.h=(int)Z_LVAL_P(p4);
		break;

	case SDL_VIDEOEXPOSE:
		to->type=type;
		//HMMM...
		to->expose.type=SDL_QUIT;
		break;

	case SDL_QUIT:
		to->type=type;
		to->expose.type=SDL_QUIT;
		break;

	case SDL_SYSWMEVENT:
		to->type=type;
		break;

	case SDL_USEREVENT:
		to->type = type;
		getArrayValueByString(from,"user",&p1);
		getArrayValueByString(*p1,"type",&p2);
		getArrayValueByString(*p1,"code",&p3);
		getArrayValueByString(*p1,"data1",&p4);
		//getArrayValueByString(*p1,"data2",&p5);
		to->user.type = Z_LVAL_P(p2);
		to->user.code = (int)Z_LVAL_P(p3);
		to->user.data1 = (void *)p4;
		to->user.data2 = NULL;
		break;
	}

	return 1;
}

// Graphics -> Array
static void graphics2array(gcn::SDLGraphics *graphics, zval *graphics_array TSRMLS_DC)
{
    zval *mTarget, *mColor;
	int handle;

	handle = zend_list_insert(graphics, le_graphics);

	array_init(graphics_array);
	add_assoc_resource(graphics_array, "handle", handle);
	zend_list_addref(handle);

	//add_assoc_bool(graphics_array, "mAlpha", graphics->mAlpha);

	//MAKE_STD_ZVAL(mTarget);
	//surf2array(graphics->mTarget, mTarget TSRMLS_CC);
	//add_assoc_zval(graphics_array, "mTarget", mTarget);

	//MAKE_STD_ZVAL(mColor);
	//add_assoc_bool(mColor, "r", graphics->mColor.r);
	//add_assoc_bool(mColor, "g", graphics->mColor.g);
	//add_assoc_bool(mColor, "b", graphics->mColor.b);
	//add_assoc_bool(mColor, "a", graphics->mColor.a);
	//add_assoc_zval(graphics_array, "mColor", mColor);
}

// Input -> Array
static void input2array(gcn::SDLInput *input, zval *input_array TSRMLS_DC)
{
	int handle;

	handle = zend_list_insert(input, le_input);

	array_init(input_array);
	add_assoc_resource(input_array, "handle", handle);
	zend_list_addref(handle);

	//add_assoc_bool(input_array, "mMouseDown", input->mMouseDown);
	//add_assoc_bool(input_array, "mMouseInWindow", input->mMouseInWindow);
}

// Container -> Array
static void container2array(gcn::Container *container, zval *container_array TSRMLS_DC)
{
	int handle;

	handle = zend_list_insert(container, le_container);

	array_init(container_array);
	add_assoc_resource(container_array, "handle", handle);
	zend_list_addref(handle);

	//add_assoc_bool(container_array, "mOpaque", container->mOpaque);
}

// Font -> Array
static void font2array(gcn::Font *font, zval *font_array TSRMLS_DC)
{
	int handle;

	handle = zend_list_insert(font, le_font);

	array_init(font_array);
	add_assoc_resource(font_array, "handle", handle);
	zend_list_addref(handle);
}

// Label -> Array
static void label2array(gcn::Label *label, zval *label_array TSRMLS_DC)
{
	int handle;

	handle = zend_list_insert(label, le_label);

	array_init(label_array);
	add_assoc_resource(label_array, "handle", handle);
	zend_list_addref(handle);
}

// Button -> Array
static void button2array(gcn::Button *button, zval *button_array TSRMLS_DC)
{
	int handle;

	handle = zend_list_insert(button, le_button);

	array_init(button_array);
	add_assoc_resource(button_array, "handle", handle);
	zend_list_addref(handle);
}

// TextBox -> Array
static void textbox2array(gcn::TextBox *textbox, zval *textbox_array TSRMLS_DC)
{
	int handle;

	handle = zend_list_insert(textbox, le_textbox);

	array_init(textbox_array);
	add_assoc_resource(textbox_array, "handle", handle);
	zend_list_addref(handle);
}

// TextField -> Array
static void textfield2array(gcn::TextField *textfield, zval *textfield_array TSRMLS_DC)
{
	int handle;

	handle = zend_list_insert(textfield, le_textfield);

	array_init(textfield_array);
	add_assoc_resource(textfield_array, "handle", handle);
	zend_list_addref(handle);
}

static int internal_sdl_peep_events(zval *events, int number, int action, int mask) {
	SDL_Event *events_array;
	int result;
	long type;
	zval *p;

	TSRMLS_FETCH();

	int typ1,i;
	typ1=0;

	type=Z_TYPE_P(p);

	switch (action) {
	case SDL_ADDEVENT:
		if (number<1) {
			mysdl_error ("events number <=0");
			return FALSE;
		}
		if (Z_TYPE_P(events)!=IS_ARRAY) {
			mysdl_error ("event parameter must be array");
			return FALSE;
		}

		if (!getArrayValueByIndex (*events,0,&p)) {
			mysdl_error ("Parameter event cannot be an empty array, used with SDL_EVENT");
			return FALSE;
		}

		if (Z_TYPE_P(p)==IS_LONG)
			typ1=1;
		else if (Z_TYPE_P(p)==IS_ARRAY)
			typ1=2;

		switch(typ1) {
		case 1:
			if (number != 1) {
				mysdl_error("SDL_ADDEVENT called with one event but numevent is >1");
				return FALSE;
			}
			events_array = (SDL_Event *)emalloc(number*sizeof(SDL_Event));
			if (!array2event (*events TSRMLS_CC, &(events_array[0]))) {
				efree(events);
				return FALSE;
			}
			break;
		case 2:
			if (getArrayCount (*events)!=number) {
				mysdl_error ("size of array of event parameter must match number param");
				return FALSE;
				events_array = (SDL_Event *)emalloc(number*sizeof(SDL_Event));
				for (i=0;i<number;i++) {
					if (!getArrayValueByIndex (*events,i,&p)) {
						mysdl_error ("Unable to fetch event element from array");
						efree(events_array);
						return FALSE;
					}
					if (Z_TYPE_P(p)!=IS_ARRAY) {
						mysdl_error("Elements of event parameter array must be arrays themselves");
						efree(events_array);
						return FALSE;
					}
					if (!array2event(*p TSRMLS_CC, &(events_array[i]))) {
						efree(events);
						return FALSE;
					}
				}
			}
			break;
		default:
			mysdl_error ("Parameter events,for SDL_ADDEVENT, must be a single event or an array of events");
			return FALSE;
		}
		break;
	case SDL_PEEKEVENT:
	case SDL_GETEVENT:
		{
			if (number < 1) {
				mysdl_error ("Parameter number must be >0 if action is SDL_PEEKEVENT or SDL_GETEVENT");
				return FALSE;
			}
			if (NULL == (events_array = (SDL_Event *)emalloc(number* sizeof(SDL_Event)))) {
				mysdl_error ("Failed to alloc events array");
				return FALSE;
			}
		}
		break;
	default:
		mysdl_error ("Parameter action must be one of SDL_ADDEVENT, SDL_PEEKEVENT or SDL_GETEVENT");
		return FALSE;
	}

	result = SDL_PeepEvents(events_array, number, (SDL_eventaction)action, mask);

	if (result != -1 && events_array  && action != SDL_ADDEVENT) {
		int i;
		zval *tmp;

		/* Now that we have called either SDL_PEEKEVENT or SDL_GETEVENT and no
		 * error occured, we need to return the events. */
		array_init(events);
		for (i = 0; i < result; i++) {
			MAKE_STD_ZVAL(tmp);
			array_init(tmp);
			if (!event2array(events_array[i], tmp TSRMLS_CC)) {
				zval_ptr_dtor(&tmp);
				efree(events_array);
				return FALSE;
			}
			add_next_index_zval(events, tmp);
		}
	}

	if (events_array) {
		efree(events_array);
	}
	return result;
}

static int cdrom2array(SDL_CD *from, zval *to) {
	int cur_track;
	int handle;

	zval *track_arr,*track;

	TSRMLS_FETCH();

	MAKE_STD_ZVAL(track_arr);
	array_init(track_arr);

	for(cur_track=0; cur_track <= SDL_MAX_TRACKS; cur_track++) {
		MAKE_STD_ZVAL(track);
		array_init(track);
		add_assoc_long(track, "id", from->track[cur_track].id);
		add_assoc_long(track, "type", from->track[cur_track].type);
		add_assoc_long(track, "unused", from->track[cur_track].unused);
		add_assoc_long(track, "length", from->track[cur_track].length);
		add_assoc_long(track, "offset", from->track[cur_track].offset);
		add_next_index_zval(track_arr, track);
	}
	handle = zend_list_insert(from, le_cdrom);
	array_init(to);
	add_assoc_resource(to, "handle", handle);
	zend_list_addref(handle);

	add_assoc_long(to, "id", from->id);
	add_assoc_long(to, "status", from->status);
	add_assoc_long(to, "numtracks", from->numtracks);
	add_assoc_long(to, "cur_track", from->cur_track);
	add_assoc_long(to, "cur_frame", from->cur_frame);
	add_assoc_zval(to, "track", track_arr);
	
	return 1;
}

static int refresh_cdrom2array(SDL_CD *from, zval *to) {
	zval *arr,*track;
	int cur_track;

	getArrayValueByString(*to,"track",&arr);

	add_assoc_long(to, "status", from->status);
	add_assoc_long(to, "numtracks", from->numtracks);
	add_assoc_long(to, "cur_track", from->cur_track);
	add_assoc_long(to, "cur_frame", from->cur_frame);

	for(cur_track=0;cur_track <= from->numtracks; cur_track++) {
		getArrayValueByIndex(*arr,cur_track,&track);
		add_assoc_long(track, "id", from->track[cur_track].id);
		add_assoc_long(track, "type", from->track[cur_track].type);
		add_assoc_long(track, "unused", from->track[cur_track].unused);
		add_assoc_long(track, "length", from->track[cur_track].length);
		add_assoc_long(track, "offset", from->track[cur_track].offset);
	}
	
	return 1;
}

static Uint32 php_sdl_timer_dispatcher(Uint32 interval, void *param) {
	php_sdl_timer *t;
	void ***tsrm_ls;
	zval *call;
	zval *params;
	zval *obj,*fun,*retval;
	Uint32 returns;

	//php_printf("Interval: %d\n",interval);
	t=(php_sdl_timer *)param;
	//php_printf("Timer id:%d\n",t->timer_id);
	call=t->callback;
	params=t->params;
	//php_printf("Callback: %X\n",call);
	//dumpaVar(*call);
	//php_printf("Dispatcher\n");
	MAKE_STD_ZVAL(retval);
	switch(Z_TYPE_P(call)) {
	case IS_ARRAY:
		//php_printf("Call is array\n");
		getArrayValueByIndex(*call,0,&obj);
		getArrayValueByIndex(*call,1,&fun);
		if (call_user_function(EG(function_table),&obj,fun,retval,1,&params TSRMLS_CC)) {
			// fail
			php_error(E_WARNING, "sdl_addTimer: callback failed");

		}
		break;
	case IS_STRING:
		//php_printf("Call is string\n");
    try {
        		if (call_user_function(EG(function_table),NULL,call,retval,1,&params TSRMLS_CC)) {
			//fail
			php_error(E_WARNING, "sdl_addTimer: callback failed");
		}


    } catch (gcn::Exception e) {
        printf("%s\n",e.getMessage());
    } catch (std::exception e) {
        printf("Std exception: %s\n",e.what());
    } catch (...) {
        printf("Unknown exception\n");
    }
		break;
	default:
		php_error(E_WARNING, "sdl_addTimer: callback not accepted");
		return 0;
		break;
	}
	convert_to_long(retval);

	returns=Z_LVAL_P(retval);
	//php_printf("Returns: %d\n",returns);
	//php_printf("Quit\n");
	return returns;
}
/* end getting from php_guichan_stuff.c*/

/*******************************
 * Stuff/Conversion Code
 *******************************/

/*******************************
 * Functions Code
 *******************************/
PHP_FUNCTION(sdl_warpmouse) {
	long x;
	long y;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &x,&y)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_warpmouse");
	}

SDL_WarpMouse(x,y);
}
PHP_FUNCTION(sdl_createcursor) {
	zval *data;
	zval *mask;
	long w;
	long h;
	long hot_x;
	long hot_y;

				long data_n, mask_n,i,handle;
				Uint8 *a_data,*a_mask;
				zval *record,*record_m;
				SDL_Cursor *cursor;			
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzllll", &data,&mask,&w,&h,&hot_x,&hot_y)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_createcursor");
	}

				data_n=getArrayCount(*data);
				mask_n=getArrayCount(*mask);
				if (data_n!=mask_n) {
					mysdl_error("sdl_createcursor: problems with data,mask dimensions"); RETURN_FALSE;
				}
				a_data=(Uint8 *)emalloc(sizeof(Uint8)*data_n);
				a_mask=(Uint8 *)emalloc(sizeof(Uint8)*mask_n);
				for (i=0;i<data_n;i++) {
					if (!getArrayValueByIndex(*data,i,&record)) {
						RETURN_FALSE;
					}
					if (!getArrayValueByIndex(*mask,i,&record_m)) {
						RETURN_FALSE;
					}
					a_data[i]=Z_LVAL_P(record);
					a_mask[i]=Z_LVAL_P(record_m);
				}
				cursor=SDL_CreateCursor(a_data,a_mask,w,h,hot_x,hot_y);
				efree(a_data); efree(a_mask);
				if (cursor) {
					handle=zend_list_insert(cursor,le_cursor);
					RETURN_RESOURCE(handle);
				}
				RETURN_FALSE;
}
PHP_FUNCTION(sdl_freecursor) {
	zval *cursor;

				SDL_Cursor *c;
				zval *handle;			    
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &cursor)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_freecursor");
	}

				if (!getArrayValueByString(*cursor,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(c,SDL_Cursor *,&handle,-1,le_cursor_name,le_cursor);
				SDL_FreeCursor(c);
				zend_list_delete(Z_LVAL_P(cursor));
}
PHP_FUNCTION(sdl_setcursor) {
	zval *cursor;

				SDL_Cursor *c;
				zval *handle;				    
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &cursor)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_setcursor");
	}

				if (!getArrayValueByString(*cursor,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(c,SDL_Cursor *,&handle,-1,le_cursor_name,le_cursor);
				SDL_FreeCursor(c);
}
PHP_FUNCTION(sdl_getcursor) {
				long handle; 
				SDL_Cursor *c;			    
			
				c=SDL_GetCursor();
				if (c) {
					handle=zend_list_insert(c,le_cursor);
					RETURN_RESOURCE(handle);
				}
				RETURN_FALSE;
}
PHP_FUNCTION(sdl_showcursor) {
	long toggle;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &toggle)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_showcursor");
	}

				RETURN_LONG(SDL_ShowCursor(toggle));
}
PHP_FUNCTION(sdl_gl_loadlibrary) {
	char *path;
	int path_length;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path,&path_length)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_gl_loadlibrary");
	}

				RETURN_LONG(SDL_GL_LoadLibrary(path));
}
PHP_FUNCTION(sdl_gl_getprocaddress) {
php_error(E_WARNING, "function %s() not implemented",get_active_function_name(TSRMLS_C));
}
PHP_FUNCTION(sdl_gl_getattribute) {
	int key;
	zval **value;

				long result;
				int v1;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz", &key,&*value)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_gl_getattribute");
	}

				result=SDL_GL_GetAttribute((SDL_GLattr)key,&v1);
				if (result==0) {
					ZVAL_LONG((*value),v1);
				}
				RETURN_LONG(result);
}
PHP_FUNCTION(sdl_gl_setattribute) {
	long key;
	long value;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &key,&value)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_gl_setattribute");
	}

				RETURN_LONG(SDL_GL_SetAttribute((SDL_GLattr)key,value));
}
PHP_FUNCTION(sdl_gl_swapbuffers) {
				SDL_GL_SwapBuffers();
}
PHP_FUNCTION(sdl_createyuvoverlay) {
	long width;
	long height;
	long format;
	zval *surf;

				SDL_Surface *s;
				SDL_Overlay *o;
				zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllz", &width,&height,&format,&surf)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_createyuvoverlay");
	}

				if (!getArrayValueByString(*surf,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
				o=SDL_CreateYUVOverlay(width,height,format,s);
				if (!o) {
					//Error
					mysdl_error("SDL_CreateYUVOverlay unable to create overlay"); 
				}
				overlay2array(o,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdl_lockyuvoverlay) {
	zval *overlay;

				SDL_Overlay *o;
				zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &overlay)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_lockyuvoverlay");
	}

				if (!getArrayValueByString(*overlay,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(o,SDL_Overlay *,&handle,-1,le_overlay_name,le_overlay);
				RETURN_LONG(SDL_LockYUVOverlay(o));
}
PHP_FUNCTION(sdl_unlockyuvoverlay) {
	zval *overlay;

				SDL_Overlay *o;
				zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &overlay)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_unlockyuvoverlay");
	}

				if (!getArrayValueByString(*overlay,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(o,SDL_Overlay *,&handle,-1,le_overlay_name,le_overlay);
				SDL_UnlockYUVOverlay(o);
}
PHP_FUNCTION(sdl_displayyuvoverlay) {
	zval *overlay;
	zval *dstrect;

				SDL_Overlay *o;
				SDL_Rect rect;
				zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &overlay,&dstrect)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_displayyuvoverlay");
	}

				
				if (!getArrayValueByString(*overlay,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(o,SDL_Overlay *,&handle,-1,le_overlay_name,le_overlay);
				array2rect(*dstrect,&rect);
				RETURN_LONG(SDL_DisplayYUVOverlay(o,&rect));
}
PHP_FUNCTION(sdl_freeyuvoverlay) {
	zval *overlay;

				SDL_Overlay *o;				
				zval *handle;
				
				long handle1;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &overlay)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_freeyuvoverlay");
	}

				if (!getArrayValueByString(*overlay,"handle",&handle)) {
					RETURN_FALSE;
				}
				handle1=Z_LVAL_P(handle);
				ZEND_FETCH_RESOURCE(o,SDL_Overlay *,&handle,-1,le_overlay_name,le_overlay);
				zend_list_delete(Z_LVAL_P(handle));
				SDL_FreeYUVOverlay(o);
}
PHP_FUNCTION(sdl_wm_setcaption) {
	char *caption;
	int caption_length;
	char *icon;
	int icon_length;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &caption,&caption_length,&icon,&icon_length)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_wm_setcaption");
	}

				SDL_WM_SetCaption(caption,icon);
}
PHP_FUNCTION(sdl_wm_getcaption) {
	zval *caption;
	zval *icon;

				char *t,*i;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &caption,&icon)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_wm_getcaption");
	}

				SDL_WM_GetCaption(&t,&i);
				ZVAL_STRING(caption,t,1);
				ZVAL_STRING(icon,i,1);
}
PHP_FUNCTION(sdl_wm_seticon) {
	zval *surf;
	zval *mask;

				SDL_Surface *s;
				Uint8 *a_mask;
				zval *handle;				
				long a_mask_n;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &surf,&mask)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_wm_seticon");
	}

				if (!getArrayValueByString(*surf,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
}
PHP_FUNCTION(sdl_wm_iconifywindow) {
SDL_WM_IconifyWindow();
}
PHP_FUNCTION(sdl_wm_togglefullscreen) {
	zval *surf;

				SDL_Surface *s;
				zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &surf)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

				
				if (!getArrayValueByString(*surf,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
				RETURN_LONG(SDL_WM_ToggleFullScreen(s));
}
PHP_FUNCTION(sdl_wm_grabinput) {
	long mode;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &mode)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_wm_grabinput");
	}

RETURN_LONG(SDL_WM_GrabInput((SDL_GrabMode)mode));
}
PHP_FUNCTION(sdl_button) {
	long x;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &x)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_button");
	}

				RETURN_LONG(SDL_PRESSED<<(x-1));
}
PHP_FUNCTION(sdl_pumpevents) {
				SDL_PumpEvents();
}
PHP_FUNCTION(sdl_pollevent) {
	zval *event;

				long result;
				SDL_Event e;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &event)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_pollevents");
	}

				
				result=SDL_PollEvent(&e);
				if (result)
					event2array(e,event TSRMLS_CC);
				RETURN_BOOL(result);
				RETURN_FALSE;
}
PHP_FUNCTION(sdl_waitevent) {
	zval *event;

				long result;
				SDL_Event e;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &event)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_waitevent");
	}

				result=SDL_WaitEvent(&e);
				event2array(e,event TSRMLS_CC);
				if (result)
					RETURN_BOOL(result);
				RETURN_FALSE;
}
PHP_FUNCTION(sdl_peepevents) {
	zval *events;
	long numevents;
	long action;
	long mask;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlll", &events,&numevents,&action,&mask)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_peepevents");
	}

				RETURN_LONG(internal_sdl_peep_events(events,numevents,action,mask));
}
PHP_FUNCTION(sdl_pushevent) {
	zval *event;

				SDL_Event e;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &event)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_pushevent");
	}

				array2event(*event TSRMLS_CC,&e);
				RETURN_BOOL(!SDL_PushEvent(&e));
}
PHP_FUNCTION(sdl_seteventfilter) {
php_error(E_WARNING, "function %s() not implemented",get_active_function_name(TSRMLS_C));
}
PHP_FUNCTION(sdl_geteventfilter) {
php_error(E_WARNING, "function %s() not implemented",get_active_function_name(TSRMLS_C));
}
PHP_FUNCTION(sdl_eventstate) {
	long type;
	long state;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &type,&state)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_eventstate");
	}

				RETURN_LONG(SDL_EventState(type,state));
}
PHP_FUNCTION(sdl_getkeystate) {
	zval *numkeys;

				int numkeys_v,i;
				Uint8 *keystate;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &numkeys)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for getkeystate");
	}

				numkeys_v = (int) Z_LVAL_P(numkeys);
				keystate = SDL_GetKeyState(&numkeys_v);
				array_init(return_value);
				for (i=0;i<numkeys_v;i++)
					add_next_index_long(return_value,keystate[i]);
				ZVAL_LONG(numkeys,numkeys_v);
}
PHP_FUNCTION(sdl_getmodstate) {
				RETURN_LONG(SDL_GetModState());
}
PHP_FUNCTION(sdl_setmodstate) {
	long modstate;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &modstate)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_setmodstate");
	}

				SDL_SetModState((SDLMod)modstate);
}
PHP_FUNCTION(sdl_getkeyname) {
	long key;

				char *keyname;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &key)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_getkeyname");
	}

				keyname = SDL_GetKeyName((SDLKey)key);
				RETURN_STRING(keyname,1);
}
PHP_FUNCTION(sdl_enableunicode) {
	long enable;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &enable)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_enableunicode");
	}

				RETURN_LONG(SDL_EnableUNICODE(enable));
}
PHP_FUNCTION(sdl_enablekeyrepeat) {
	long delay;
	long interval;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &delay,&interval)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_enablekeyrepeat");
	}

				RETURN_LONG(SDL_EnableKeyRepeat(delay, interval));
}
PHP_FUNCTION(sdl_getmousestate) {
	zval *x;
	zval *y;

				int ret,x1,y1;
				x1=Z_LVAL_P(x);
				y1=Z_LVAL_P(x);
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &x,&y)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_getmousestate");
	}

				ret=SDL_GetMouseState(&x1,&y1);
				ZVAL_LONG(x,x1);
				ZVAL_LONG(y,y1);
				RETURN_LONG(ret);
}
PHP_FUNCTION(sdl_getrelativemousestate) {
	zval *x;
	zval *y;

				int ret,x1,y1;
				x1=Z_LVAL_P(x);
				y1=Z_LVAL_P(x);
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &x,&y)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_getrelativemousestate");
	}

				ret=SDL_GetRelativeMouseState(&x1,&y1);
				ZVAL_LONG(x,x1);
				ZVAL_LONG(y,y1);		
				RETURN_LONG(ret);
}
PHP_FUNCTION(sdl_getappstate) {
				RETURN_LONG(SDL_GetAppState());
}
PHP_FUNCTION(sdl_numjoysticks) {
				RETURN_LONG(SDL_NumJoysticks());
}
PHP_FUNCTION(sdl_joystickname) {
	long device_index;

				char *name;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &device_index)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joystickname");
	}

				if (NULL == (name = (char *)SDL_JoystickName(device_index))) {
					RETURN_FALSE;
				}
				RETURN_STRING(name,1);
}
PHP_FUNCTION(sdl_joystickopen) {
	long device_index;

				SDL_Joystick *joystick;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &device_index)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joystickopen");
	}

				if (NULL == (joystick = SDL_JoystickOpen(device_index))) {
					mysdl_error("could not open joystick");
					RETURN_FALSE;
				}
				ZEND_REGISTER_RESOURCE(return_value, joystick, le_joystick);
}
PHP_FUNCTION(sdl_joystickopened) {
	long device_index;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &device_index)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joystickopened");
	}

				RETURN_BOOL(SDL_JoystickOpened(device_index));
}
PHP_FUNCTION(sdl_joystickindex) {
	zval *joystick;

				SDL_Joystick *j;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &joystick)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joystickindex");
	}

				ZEND_FETCH_RESOURCE(j,SDL_Joystick *,&joystick,-1,le_joystick_name,le_joystick);
				RETURN_LONG(SDL_JoystickIndex(j));
}
PHP_FUNCTION(sdl_joysticknumaxes) {
	zval *joystick;

				SDL_Joystick *j;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &joystick)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joysticknumaxes");
	}

				ZEND_FETCH_RESOURCE(j,SDL_Joystick *,&joystick,-1,le_joystick_name,le_joystick);
				RETURN_LONG(SDL_JoystickNumAxes(j));
}
PHP_FUNCTION(sdl_joysticknumballs) {
	zval *joystick;

				SDL_Joystick *j;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &joystick)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joysticknumballs");
	}

				ZEND_FETCH_RESOURCE(j,SDL_Joystick *,&joystick,-1,le_joystick_name,le_joystick);
				RETURN_LONG(SDL_JoystickNumBalls(j));
}
PHP_FUNCTION(sdl_joysticknumhats) {
	zval *joystick;

				SDL_Joystick *j;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &joystick)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joysticknumhats");
	}

				ZEND_FETCH_RESOURCE(j,SDL_Joystick *,&joystick,-1,le_joystick_name,le_joystick);
				RETURN_LONG(SDL_JoystickNumHats(j));
}
PHP_FUNCTION(sdl_joysticknumbuttons) {
	zval *joystick;

				SDL_Joystick *j;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &joystick)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joysticknumbuttons");
	}

				ZEND_FETCH_RESOURCE(j,SDL_Joystick *,&joystick,-1,le_joystick_name,le_joystick);
				RETURN_LONG(SDL_JoystickNumButtons(j));
}
PHP_FUNCTION(sdl_joystickupdate) {
				SDL_JoystickUpdate();
}
PHP_FUNCTION(sdl_joystickeventstate) {
	long state;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &state)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joystickeventstate");
	}

				RETURN_LONG(SDL_JoystickEventState(state));
}
PHP_FUNCTION(sdl_joystickgetaxis) {
	zval *joystick;
	long axis;

				SDL_Joystick *j;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &joystick,&axis)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joystickgetaxis");
	}

				ZEND_FETCH_RESOURCE(j,SDL_Joystick *,&joystick,-1,le_joystick_name,le_joystick);
				RETURN_LONG(SDL_JoystickGetAxis(j, axis));
}
PHP_FUNCTION(sdl_joystickgethat) {
	zval *joystick;
	long hat;

				SDL_Joystick *j;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &joystick,&hat)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joystickgethat");
	}

				ZEND_FETCH_RESOURCE(j,SDL_Joystick *,&joystick,-1,le_joystick_name,le_joystick);
				RETURN_LONG(SDL_JoystickGetHat(j, hat));
}
PHP_FUNCTION(sdl_joystickgetball) {
	zval *joystick;
	int ball;

				SDL_Joystick *j;				
				int dx,dy;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &joystick,&ball)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joystickgetball");
	}

				ZEND_FETCH_RESOURCE(j,SDL_Joystick *,&joystick,-1,le_joystick_name,le_joystick);
				if (-1 == SDL_JoystickGetBall(j, ball, &dx, &dy)) {
					RETURN_FALSE;
				} else {
					array_init(return_value);
					add_next_index_long(return_value, dx);
					add_next_index_long(return_value, dy);
				}
}
PHP_FUNCTION(sdl_joystickgetbutton) {
	zval *joystick;
	long button;

				SDL_Joystick *j;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &joystick,&button)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joystickgetbutton");
	}

				ZEND_FETCH_RESOURCE(j,SDL_Joystick *,&joystick,-1,le_joystick_name,le_joystick);
				RETURN_BOOL(SDL_JoystickGetButton(j, button));
}
PHP_FUNCTION(sdl_joystickclose) {
	zval *joystick;

				SDL_Joystick *j;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &joystick)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_joystickclose");
	}

				ZEND_FETCH_RESOURCE(j,SDL_Joystick *,&joystick,-1,le_joystick_name,le_joystick);
				zend_list_delete(Z_RESVAL_P(joystick));
}
PHP_FUNCTION(sdl_cd_indrive) {
	long status;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &status)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_cd_indrive");
	}

				RETURN_LONG(CD_INDRIVE(status));
}
PHP_FUNCTION(sdl_frames_to_msf) {
	long frame;

				long m,s,f;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &frame)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_frames_to_msf");
	}

				FRAMES_TO_MSF(frame,&m,&s,&f);
				array_init(return_value);
				add_next_index_long(return_value, m);
				add_next_index_long(return_value, s);
				add_next_index_long(return_value, f);
}
PHP_FUNCTION(sdl_msf_to_frames) {
	long m;
	long s;
	long f;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &m,&s,&f)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_msf_to_frames");
	}

				RETURN_LONG(MSF_TO_FRAMES(m, s, f));
}
PHP_FUNCTION(sdl_cdnumdrives) {
				RETURN_LONG(SDL_CDNumDrives());
}
PHP_FUNCTION(sdl_cdname) {
	long drive;

				char *name;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &drive)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_cdname");
	}

				name = (char *)SDL_CDName(drive);
				RETURN_STRING(estrndup(name,strlen(name)),0);
}
PHP_FUNCTION(sdl_cdopen) {
	long drive;

				SDL_CD *cdrom;
				zval **track_arr,**track;
				long cur_track;
				long handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &drive)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_cdopen");
	}

				cdrom=SDL_CDOpen(drive);
				if (!cdrom) {
					// manage error.
					RETURN_FALSE;
				}
				cdrom2array(cdrom,return_value);
}
PHP_FUNCTION(sdl_cdstatus) {
	zval *cdrom;

				SDL_CD *cd;
				zval *handle;
				long status;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &cdrom)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_cdstatus");
	}

	
				if (!getArrayValueByString(*cdrom,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(cd, SDL_CD *, &handle, -1, le_cdrom_name, le_cdrom);
				
				status = SDL_CDStatus(cd);
				refresh_cdrom2array(cd,cdrom);
}
PHP_FUNCTION(sdl_cdplay) {
	zval *cdrom;
	long start;
	long length;

				SDL_CD *cd;
				zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll", &cdrom,&start,&length)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_cdplay");
	}

				if (!getArrayValueByString(*cdrom,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(cd, SDL_CD *, &handle, -1, le_cdrom_name, le_cdrom);
				RETURN_LONG(SDL_CDPlay(cd, start, length));
}
PHP_FUNCTION(sdl_cdplaytracks) {
	zval *cdrom;
	long start_track;
	long start_frame;
	long ntracks;
	long nframes;

				SDL_CD *cd;
				zval *handle;
				long ret;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &cdrom,&start_track,&start_frame,&ntracks,&nframes)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_cdplay");
	}

				if (!getArrayValueByString(*cdrom,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(cd, SDL_CD *, &handle, -1, le_cdrom_name, le_cdrom);
				if (-1 == (ret = SDL_CDPlayTracks(cd, start_track, start_frame, ntracks, nframes))) {
					RETURN_FALSE;
				} else {
					RETURN_LONG(ret);
				}
}
PHP_FUNCTION(sdl_cdpause) {
	zval *cdrom;

				SDL_CD *cd;
				zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &cdrom)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_cdpause");
	}

				if (!getArrayValueByString(*cdrom,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(cd, SDL_CD *, &handle, -1, le_cdrom_name, le_cdrom);
				RETURN_LONG(SDL_CDPause(cd));
}
PHP_FUNCTION(sdl_cdresume) {
	zval *cdrom;

				SDL_CD *cd;
				zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &cdrom)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_cdresume");
	}

				if (!getArrayValueByString(*cdrom,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(cd, SDL_CD *, &handle, -1, le_cdrom_name, le_cdrom);
				RETURN_LONG(SDL_CDResume(cd));
}
PHP_FUNCTION(sdl_cdstop) {
	zval *cdrom;

				SDL_CD *cd;
				zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &cdrom)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_cdstop");
	}

				if (!getArrayValueByString(*cdrom,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(cd, SDL_CD *, &handle, -1, le_cdrom_name, le_cdrom);
				RETURN_LONG(SDL_CDStop(cd));
}
PHP_FUNCTION(sdl_cdeject) {
	zval *cdrom;

				SDL_CD *cd;
				zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &cdrom)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_cdeject");
	}

				if (!getArrayValueByString(*cdrom,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(cd, SDL_CD *, &handle, -1, le_cdrom_name, le_cdrom);
				RETURN_LONG(SDL_CDEject(cd));
}
PHP_FUNCTION(sdl_cdclose) {
	zval *cdrom;

				SDL_CD *cd;
				zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &cdrom)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_cdclose");
	}

				if (!getArrayValueByString(*cdrom,"handle",&handle)) {
					RETURN_FALSE;
				}
				ZEND_FETCH_RESOURCE(cd, SDL_CD *, &handle, -1, le_cdrom_name, le_cdrom);
				//handle = Z_LVAL_PP(handle);
				zend_list_delete(Z_LVAL_P(handle));

				SDL_CDClose(cd);
}
PHP_FUNCTION(sdl_createmutex) {
				SDL_mutex *m;
			
				if (NULL == (m = SDL_CreateMutex())) {
					RETURN_FALSE;
				}
				ZEND_REGISTER_RESOURCE(return_value, m, le_mutex);
}
PHP_FUNCTION(sdl_destroymutex) {
	zval *mutex;

				SDL_mutex *m;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &mutex)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_destroymutex");
	}

				ZEND_FETCH_RESOURCE(m,SDL_mutex *,&mutex,-1,le_mutex_name,le_mutex);
				SDL_DestroyMutex(m);
				zend_list_delete(Z_RESVAL_P(mutex));
}
PHP_FUNCTION(sdl_mutexp) {
	zval *mutex;

				SDL_mutex *m;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &mutex)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_mutexp");
	}

				ZEND_FETCH_RESOURCE(m,SDL_mutex *,&mutex,-1,le_mutex_name,le_mutex);
				RETURN_LONG(SDL_mutexP(m));
}
PHP_FUNCTION(sdl_mutexv) {
	zval *mutex;

				SDL_mutex *m;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &mutex)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_mutexv");
	}

				ZEND_FETCH_RESOURCE(m,SDL_mutex *,&mutex,-1,le_mutex_name,le_mutex);
				RETURN_LONG(SDL_mutexV(m));
}
PHP_FUNCTION(sdl_getticks) {
				RETURN_LONG(SDL_GetTicks());
}
PHP_FUNCTION(sdl_delay) {
	long ms;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ms)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_delay");
	}

				SDL_Delay(ms);
}
PHP_FUNCTION(sdl_addtimer) {
	long interval;
	zval *callback;
	zval *params;

				php_sdl_timer *t;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lzz", &interval,&callback,&params)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_addtimer");
	}

				t=(php_sdl_timer *)emalloc(sizeof(php_sdl_timer));
				//ZVAL_ADDREF(callback);
				Z_ADDREF_P(callback);
				//ZVAL_ADDREF(params);
				Z_ADDREF_P(params);
				t->callback=callback;
				t->params=params;
				t->timer_id=SDL_AddTimer(interval,php_sdl_timer_dispatcher,(void *)t);
				ZEND_REGISTER_RESOURCE(return_value,t,le_timer);
}
PHP_FUNCTION(sdl_removetimer) {
	zval *id;

				php_sdl_timer *t;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &id)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_removetimer");
	}

				ZEND_FETCH_RESOURCE(t,php_sdl_timer *,&id,-1,le_timer_name,le_timer);
				SDL_RemoveTimer(t->timer_id);				
				//ZVAL_DELREF(t->callback);
				Z_DELREF_P(t->callback);
				//ZVAL_DELREF(t->params);
				Z_DELREF_P(t->params);
				zend_list_delete(Z_RESVAL_P(id));
}
PHP_FUNCTION(sdl_init) {
	long flags;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flags)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_init");
	}

		    if (SDL_Init(flags)==-1) { 
		        mysdl_error("SDL_Init"); 
		        RETURN_FALSE; 
		    } 
		    RETURN_TRUE;
}
PHP_FUNCTION(sdl_initsubsystem) {
	long flags;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flags)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_initsubsystem");
	}

if (SDL_InitSubSystem(flags)==-1) { mysdl_error("SDL_InitSubSystem"); RETURN_FALSE; } RETURN_TRUE;
}
PHP_FUNCTION(sdl_quitsubsystem) {
	long flags;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flags)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for quitsubsystem");
	}

SDL_QuitSubSystem(flags);
}
PHP_FUNCTION(sdl_wasinit) {
	long flags;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flags)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_wasinit");
	}

RETURN_LONG(SDL_WasInit(flags));
}
PHP_FUNCTION(sdl_quit) {
SDL_Quit();
}
PHP_FUNCTION(sdl_geterror) {
RETURN_STRING(SDL_GetError(),0);
}
PHP_FUNCTION(sdl_mustlock) {
	zval *surf;

			zval *handle;
			SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &surf)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_mustlock");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				mysdl_error("SDL_MUSTLOCK");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		 	RETURN_LONG(SDL_MUSTLOCK(s));
}
PHP_FUNCTION(sdl_getvideosurface) {
		SDL_Surface *surf;
			
        surf=SDL_GetVideoSurface();
		if (!surf) { mysdl_error("couldn't get surface"); RETURN_FALSE }
		surf2array(surf, return_value TSRMLS_CC);
}
PHP_FUNCTION(sdl_getvideoinfo) {
		SDL_VideoInfo *vi;
			
        vi=(SDL_VideoInfo *)SDL_GetVideoInfo();
		if (!vi) { mysdl_error("couldn't get video information"); RETURN_FALSE }
		videoinfo2array(vi,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdl_videodrivername) {
            char name[256];
			
RETURN_STRING(SDL_VideoDriverName((char *)name,255),1);
}
PHP_FUNCTION(sdl_listmodes) {
	zval *format;
	long flags;

			zval *dest,*ret1;
			SDL_PixelFormat pf1;	
			SDL_Rect **modes;
			long i;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &format,&flags)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_listmodes");
	}

			modes=(SDL_Rect **)0;
			if (getArrayValueByString(*format,"BitsPerPixel",&dest)) {
				pf1.BitsPerPixel=Z_LVAL_P(dest);
				//php_error(E_WARNING,"BPP: %d",Z_LVAL_P(dest));
				modes = SDL_ListModes(&pf1, flags);					
			} else {
				modes = SDL_ListModes(NULL, flags);
			}
			if (modes==(SDL_Rect **)-1) {
				RETURN_LONG(-1);
			}
			if (modes==(SDL_Rect **)0) {
				mysdl_error("SDL_ListModes, no mode available");
				RETURN_FALSE;
			}
			for (i=0;modes[i];++i) {					
				MAKE_STD_ZVAL(ret1);
				array_init(ret1);
				add_assoc_long(ret1, "x", modes[i]->x);
				add_assoc_long(ret1, "y", modes[i]->y);
				add_assoc_long(ret1, "w", modes[i]->w);
				add_assoc_long(ret1, "h", modes[i]->h);
				add_next_index_zval(return_value,ret1);					
			}
}
PHP_FUNCTION(sdl_videomodeok) {
	long width;
	long height;
	long bpp;
	long flags;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll", &width,&height,&bpp,&flags)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_videomodeok");
	}

RETURN_LONG(SDL_VideoModeOK(width,height,bpp,flags));
}
PHP_FUNCTION(sdl_setvideomode) {
	long width;
	long height;
	long bpp;
	long flags;

			SDL_Surface *surf;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll", &width,&height,&bpp,&flags)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_setvideomode");
	}

            surf=SDL_SetVideoMode(width,height,bpp,flags); 
			if (!surf) { mysdl_error("couldnt create surface"); RETURN_FALSE; }					
			surf2array(surf,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdl_updaterect) {
	zval *surf;
	long x;
	long y;
	long width;
	long height;

			zval *handle;
			SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &surf,&x,&y,&width,&height)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_updaterect");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				mysdl_error("SDL_UpdateRect");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		 	SDL_UpdateRect(s,x,y,width,height);
}
PHP_FUNCTION(sdl_updaterects) {
	zval *surf;
	long numrects;
	zval *rects;

			zval *handle,*x,*y,*w,*h,*e;
			SDL_Surface *s;
			long n_rects,i;
			SDL_Rect *r;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlz", &surf,&numrects,&rects)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_updaterects");
	}

			n_rects=zend_hash_next_free_element(Z_ARRVAL_P(rects));

			if (numrects>n_rects) numrects=n_rects;
			if (numrects==0) RETURN_FALSE;
			if (!getArrayValueByString(*surf,"handle",&handle)) {
				mysdl_error("SDL_UpdateRects");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);

			r=(SDL_Rect *)emalloc(numrects*sizeof(SDL_Rect));
			for (i=0;i<numrects;i++) {
				if (!getArrayValueByIndex(*rects,i,&e)) {
					mysdl_error("SDL_UpdateRects error getting data");
					RETURN_FALSE;
				}
				array2rect(*e,&(r[i]));
			}
			SDL_UpdateRects(s,numrects,r);
			efree(r);
}
PHP_FUNCTION(sdl_flip) {
	zval *surf;

			zval *handle;
			SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &surf)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_flip");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				mysdl_error("SDL_Flip");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		 	RETURN_LONG(SDL_Flip(s));
}
PHP_FUNCTION(sdl_setcolors) {
	zval *surf;
	zval *colors;
	long firstcolor;
	long ncolors;

			zval *color,*r,*g,*b;
			SDL_Color *colors1;
			long i;
			long result;
			zval *handle;
			SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzll", &surf,&colors,&firstcolor,&ncolors)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_setcolors");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				mysdl_error("SDL_SetColors");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);

		 	colors1  = (SDL_Color *)emalloc(ncolors*sizeof(SDL_Color));
		 	for (i=0;i<ncolors;i++) {
				if (!getArrayValueByIndex(*colors,i,&color)) {
					RETURN_FALSE;
					mysdl_error("SDL_SetColors, getting data");
				}

				getArrayValueByString(*color,"r",&r);
				getArrayValueByString(*color,"g",&g);					
				getArrayValueByString(*color,"r",&b);					
				colors1[i].r=Z_LVAL_P(r);
				colors1[i].g=Z_LVAL_P(g);					
				colors1[i].r=Z_LVAL_P(b);					
			}						 	
			result = SDL_SetColors(s, colors1, firstcolor, ncolors);
			RETURN_LONG(result);
}
PHP_FUNCTION(sdl_setpalette) {
	zval *surf;
	long flags;
	zval *colors;
	long firstcolor;
	long ncolors;

			zval *color,*r,*g,*b;
			SDL_Color *colors1;
			long i;
			long result;
			zval *handle;
			SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlzll", &surf,&flags,&colors,&firstcolor,&ncolors)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_setpalette");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				mysdl_error("sdl_setpalette");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		 	colors1  = (SDL_Color *)emalloc(ncolors*sizeof(SDL_Color));

		 	for (i=0;i<ncolors;i++) {					
				if (!getArrayValueByIndex(*colors,i,&color))
					RETURN_FALSE;
				if (!getArrayValueByString(*color,"r",&r)) 
					RETURN_FALSE;
				if (!getArrayValueByString(*color,"g",&g))
					RETURN_FALSE;
				if (!getArrayValueByString(*color,"b",&b))
					RETURN_FALSE;
				colors1[i].r=Z_LVAL_P(r);
				colors1[i].g=Z_LVAL_P(g);					
				colors1[i].b=Z_LVAL_P(b);					
			}
					 	
			result = SDL_SetPalette(s, flags, colors1, firstcolor, ncolors);
			RETURN_LONG(result);
}
PHP_FUNCTION(sdl_setgamma) {
	float r;
	float g;
	float b;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ddd", &r,&g,&b)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_setgamma");
	}

		RETURN_LONG(SDL_SetGamma(r,g,b));
}
PHP_FUNCTION(sdl_getgammaramp) {
	zval *redtable;
	zval *greentable;
	zval *bluetable;

			Uint16 r[256],g[256],b[256];
			long result,i;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &redtable,&greentable,&bluetable)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_getgammaramp");
	}

			result=SDL_GetGammaRamp(r,g,b);
			if (result==-1) RETURN_LONG(result);
			array_init(redtable);
			array_init(greentable);
			array_init(bluetable);
			for (i=0;i<256;i++) {
				add_index_long(redtable,i,r[i]);
				add_index_long(greentable,i,g[i]);					
				add_index_long(bluetable,i,b[i]);										
			}
			RETURN_LONG(result);
}
PHP_FUNCTION(sdl_setgammaramp) {
	zval *redtable;
	zval *greentable;
	zval *bluetable;

			Uint16 r[256],g[256],b[256];
			zval *r1, *g1, *b1;
			long result,i;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &redtable,&greentable,&bluetable)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_setgammaramp");
	}

			if (
				Z_TYPE_P(redtable)!=IS_ARRAY ||
				Z_TYPE_P(greentable)!=IS_ARRAY ||
				Z_TYPE_P(bluetable)!=IS_ARRAY
			) RETURN_FALSE;

			for (i=0;i<256;i++) {
				if (getArrayValueByIndex(*redtable,i,&r1)) {
					r[i]=Z_LVAL_P(r1);
				} else {
					r[i]=0;
				}
				if (getArrayValueByIndex(*greentable,i,&g1)) {
					g[i]=Z_LVAL_P(g1);
				} else {
					g[i]=0;
				}
				if (getArrayValueByIndex(*bluetable,i,&b1)) {
					b[i]=Z_LVAL_P(b1);
				} else {
					b[i]=0;
				}
			}
			RETURN_LONG(SDL_SetGammaRamp(r, g, b));
}
PHP_FUNCTION(sdl_maprgb) {
	zval *fmt;
	long r;
	long g;
	long b;

			SDL_PixelFormat *f;
			zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlll", &fmt,&r,&g,&b)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_maprgb");
	}

			if (!getArrayValueByString(*fmt,"handle",&handle)) {
				mysdl_error("SDL_MapRGB");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(f,SDL_PixelFormat *,&handle,-1,le_pixelformat_name,le_pixelformat);
			RETURN_LONG((unsigned long)SDL_MapRGB(f,(Uint8)r,(Uint8)g,(Uint8)b));
}
PHP_FUNCTION(sdl_maprgba) {
	zval *fmt;
	long r;
	long g;
	long b;
	long a;

			SDL_PixelFormat *f;
			zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &fmt,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_maprgba");
	}

			if (!getArrayValueByString(*fmt,"handle",&handle)) {
				mysdl_error("SDL_MapRGBA");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(f,SDL_PixelFormat *,&handle,-1,le_pixelformat_name,le_pixelformat);
			RETURN_LONG((unsigned long)SDL_MapRGBA(f,(Uint8)r,(Uint8)g,(Uint8)b,(Uint8)a));
}
PHP_FUNCTION(sdl_getrgb) {
	long pixel;
	zval *fmt;
	zval *r;
	zval *g;
	zval *b;

			Uint8 r1,g1,b1;				
			SDL_PixelFormat *f;
			zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lzzzz", &pixel,&fmt,&r,&g,&b)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_getrgb");
	}

			if (!getArrayValueByString(*fmt,"handle",&handle)) {					
				mysdl_error("SDL_GetRGB");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(f,SDL_PixelFormat *,&handle,-1,le_pixelformat_name,le_pixelformat);
		 	SDL_GetRGB(pixel, f, &r1, &g1, &b1);
		 	ZVAL_LONG(r,r1);
		 	ZVAL_LONG(g,g1);
		 	ZVAL_LONG(b,b1);			 
}
PHP_FUNCTION(sdl_getrgba) {
	long pixel;
	zval *fmt;
	zval *r;
	zval *g;
	zval *b;
	zval *a;

			Uint8 r1,g1,b1,a1;
			SDL_PixelFormat *f;
			zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lzzzzz", &pixel,&fmt,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_getrgba");
	}

			if (!getArrayValueByString(*fmt,"handle",&handle)) {
				mysdl_error("SDL_GetRGBA");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(f,SDL_PixelFormat *,&handle,-1,le_pixelformat_name,le_pixelformat);
		 	SDL_GetRGBA(pixel, f, &r1, &g1, &b1, &a1);
		 	ZVAL_LONG(r,r1);
		 	ZVAL_LONG(g,g1);
		 	ZVAL_LONG(b,b1);
		 	ZVAL_LONG(a,a1);
}
PHP_FUNCTION(sdl_creatergbsurface) {
	long flags;
	long width;
	long height;
	long depth;
	long Rmask;
	long Gmask;
	long Bmask;
	long Amask;

			SDL_Surface *surf;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llllllll", &flags,&width,&height,&depth,&Rmask,&Gmask,&Bmask,&Amask)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_creatergbsurface");
	}

			surf=SDL_CreateRGBSurface(flags, width, height, depth, Rmask, Gmask, Bmask, Amask);
			//php_error(E_WARNING, "Create RGB Surf (flags:%d, w:%d, h:%d, d:%d",flags,width,height,depth);
			if (!surf) { mysdl_error("couldnt create surface"); RETURN_FALSE; }
			surf2array(surf,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdl_creatergbsurfacefrom) {
	zval *buffer;
	long width;
	long height;
	long depth;
	long pitch;
	long Rmask;
	long Gmask;
	long Bmask;
	long Amask;

			long lenstr,len2;
			SDL_Surface *surf;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllllll", &buffer,&width,&height,&depth,&pitch,&Rmask,&Gmask,&Bmask,&Amask)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_creatergbsurfacefrom");
	}

			lenstr=Z_STRLEN_P(buffer);
			len2=(depth/8)*width*height;
			if (lenstr==len2) {
				surf=SDL_CreateRGBSurfaceFrom(
					(void *)Z_LVAL_P(buffer),width,height,depth,pitch,
					Rmask,Gmask,Bmask,Amask
				);
				if (!surf) { mysdl_error("couldnt create surface"); RETURN_FALSE; }
				surf2array(surf,return_value TSRMLS_CC);
			} else {
				mysdl_error("couldnt create surface (size of string)"); 
				//php_write("%d != %d\n",lenstr,len2);
				RETURN_FALSE;
			}
}
PHP_FUNCTION(sdl_freesurface) {
	zval *surf;

			SDL_Surface *s;
			SDL_PixelFormat *f;
			zval *handle,*format;				
			long handle1;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &surf)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_freesurface");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				RETURN_FALSE;
			}
			handle1=Z_LVAL_P(handle);				
			ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		 	zend_list_delete(Z_LVAL_P(handle));
			if (!getArrayValueByString(*surf,"format",&format)) {
				mysdl_error("SDL_FreeSurface, getting surface");
				RETURN_FALSE;
			}
			if (!getArrayValueByString(*format,"handle",&handle)) {
				mysdl_error("SDL_FreeSurface, getting format");
				RETURN_FALSE;
			}
			handle1=Z_LVAL_P(handle);
		 	ZEND_FETCH_RESOURCE(f,SDL_PixelFormat *,&handle,-1,le_pixelformat_name,le_pixelformat);
		 	zend_list_delete(handle1);
		 	SDL_FreeSurface(s);
}
PHP_FUNCTION(sdl_locksurface) {
	zval *surf;

			zval *handle;
			SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &surf)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_locksurface");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				mysdl_error("SDL_LockSurface");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		 	RETURN_LONG(SDL_LockSurface(s));
}
PHP_FUNCTION(sdl_unlocksurface) {
	zval *surf;

			zval *handle;
			SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &surf)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_unlocksurface");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				mysdl_error("SDL_UnlockSurface");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		 	SDL_UnlockSurface(s);
}
PHP_FUNCTION(sdl_loadbmp) {
	char *file;
	int file_length;

		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file,&file_length)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_loadbmp");
	}

        s=SDL_LoadBMP(file);
		if (!s) { mysdl_error("couldnt create surface"); RETURN_FALSE; }
		surf2array(s,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdl_savebmp) {
	zval *surf;
	char *file;
	int file_length;

			zval *handle;
			SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &surf,&file,&file_length)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_savebmp");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				mysdl_error("SDL_SaveBMP");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		 	RETURN_LONG(SDL_SaveBMP(s,file));
}
PHP_FUNCTION(sdl_setcolorkey) {
	zval *surf;
	long flag;
	long key;

			zval *handle;
			SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll", &surf,&flag,&key)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_setcolorkey");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				mysdl_error("SDL_SetColorKey");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
			RETURN_LONG(SDL_SetColorKey(s,flag,key));
}
PHP_FUNCTION(sdl_setalpha) {
	zval *surf;
	long flag;
	long alpha;

			zval *handle;
			SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll", &surf,&flag,&alpha)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_setalpha");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				mysdl_error("SDL_SetAlpha");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
			RETURN_LONG(SDL_SetColorKey(s,flag,alpha));
}
PHP_FUNCTION(sdl_setcliprect) {
	zval *surf;
	zval *rect;

			SDL_Surface *s;
			SDL_Rect r;				
			zval *handle1,*handle2;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &surf,&rect)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_setcliprect");
	}

			if (!getArrayValueByString(*surf,"handle",&handle1)) {
				mysdl_error("SDL_SetClipRect");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle1,-1,le_surface_name,le_surface);

			/* to go on */
			/* search for x,y,w,h in array rect. */			
			array2rect(*rect,&r);

			SDL_SetClipRect(s, &r);

			if (!getArrayValueByString(*surf,"clip_rect",&handle2)) {					
				mysdl_error("SDL_SetClipRect, 2");
				RETURN_FALSE;
			}
			rect2array(s->clip_rect,handle2);
			add_assoc_long(handle2,"x",s->clip_rect.x);
			add_assoc_long(handle2,"y",s->clip_rect.y);				
			add_assoc_long(handle2,"w",s->clip_rect.w);				
			add_assoc_long(handle2,"h",s->clip_rect.h);
}
PHP_FUNCTION(sdl_getcliprect) {
	zval *surf;
	zval *rect;

			SDL_Rect r;
			zval *handle;
			SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &surf,&rect)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_getcliprect");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				mysdl_error("SDL_GetClipRect");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
			SDL_GetClipRect(s,&r);
			rect2array(r,rect);
}
PHP_FUNCTION(sdl_convertsurface) {
	zval *surf;
	zval *pf;
	long flags;

			SDL_Surface *s,*d;
			SDL_PixelFormat *f;				
			zval *handle1,*handle2;			    
		
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzl", &surf,&pf,&flags)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_convertsurface");
	}

			if (!getArrayValueByString(*surf,"handle",&handle1)) {
				RETURN_FALSE;
			}
			ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle1,-1,le_surface_name,le_surface);
			if (!getArrayValueByString(*pf,"handle",&handle2)) {
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(f,SDL_PixelFormat *,&handle2,-1,le_pixelformat_name,le_pixelformat);
		 	d=SDL_ConvertSurface(s,f,flags);
			surf2array(d,return_value TSRMLS_CC); 
}
PHP_FUNCTION(sdl_blitsurface) {
	zval *src;
	zval *srcrect;
	zval *dst;
	zval *dstrect;

			SDL_Surface *s,*d;
			SDL_Rect sr,dr;
			zval *handle;				
			long srcrect_null, dstrect_null;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzz", &src,&srcrect,&dst,&dstrect)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_blitsurface");
	}

			if (!getArrayValueByString(*src,"handle",&handle)) {
				RETURN_FALSE;
			}
			ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
			if (!getArrayValueByString(*dst,"handle",&handle)) {
				RETURN_FALSE;
			}
			ZEND_FETCH_RESOURCE(d,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
			srcrect_null=(Z_TYPE_P(srcrect)==IS_ARRAY)?0:1;
			dstrect_null=(Z_TYPE_P(dstrect)==IS_ARRAY)?0:1;
			if (dstrect_null==0) {
				array2rect(*dstrect,&dr);
			}
			if (srcrect_null==0) {
				array2rect(*srcrect,&sr);
			}
			RETURN_LONG(SDL_BlitSurface(s, (srcrect_null) ? NULL : &sr, d, (dstrect_null) ? NULL : &dr));
}
PHP_FUNCTION(sdl_fillrect) {
	zval *surf;
	zval *rect;
	long color;

			SDL_Surface *s;
			SDL_PixelFormat *f;
			zval *handle,*format;				
			SDL_Rect r;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzl", &surf,&rect,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_fillrect");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				RETURN_FALSE;
			}
			ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
			if (!getArrayValueByString(*surf,"format",&format)) {
				mysdl_error("SDL_FreeSurface, getting surface");
				RETURN_FALSE;
			}
			if (!getArrayValueByString(*format,"handle",&handle)) {
				mysdl_error("SDL_FreeSurface, getting format");
				RETURN_FALSE;
			}
		 	ZEND_FETCH_RESOURCE(f,SDL_PixelFormat *,&handle,-1,le_pixelformat_name,le_pixelformat);
			array2rect(*rect,&r);
			RETURN_LONG(SDL_FillRect(s, &r, color));
}
PHP_FUNCTION(sdl_displayformat) {
	zval *surf;

			SDL_Surface *s,*d;
			zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &surf)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_displayformat");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				RETURN_FALSE;
			}
			ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		 	d=SDL_DisplayFormat(s);
		 	if (!d) {
				php_error(E_WARNING, "%s() unable to create new surface: %s",
					get_active_function_name(TSRMLS_C),SDL_GetError());			 	
				RETURN_FALSE;
		 	}
			surf2array(d,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdl_displayformatalpha) {
	zval *surf;

			SDL_Surface *s,*d;
			zval *handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &surf)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdl_displayformatalpha");
	}

			if (!getArrayValueByString(*surf,"handle",&handle)) {
				RETURN_FALSE;
			}
			ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		 	d=SDL_DisplayFormatAlpha(s);
		 	if (!d) {
				php_error(E_WARNING, "%s() unable to create new surface: %s",
					get_active_function_name(TSRMLS_C),SDL_GetError());			 	
				RETURN_FALSE;
		 	}
			surf2array(d,return_value TSRMLS_CC);
}
PHP_FUNCTION(guichan_init) {
	zval *surf;

    	SDL_Surface *screen;
        zval *handle1;
        gcn::SDLImageLoader* imageLoader;
        
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &surf)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for guichan_init");
	}

        if (!getArrayValueByString(*surf,"handle",&handle1)) {
        	RETURN_FALSE;
        }
        ZEND_FETCH_RESOURCE(screen,SDL_Surface *,&handle1,-1,le_surface_name,le_surface);

	    globals::gui = new gcn::Gui();
        imageLoader = new gcn::SDLImageLoader();
        gcn::Image::setImageLoader(imageLoader);
}
PHP_FUNCTION(guichan_newgraphics) {
	zval *surf;

    	SDL_Surface *screen;
        zval *handle1;

        gcn::SDLGraphics* graphics;
        
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &surf)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for guichan_newgraphics");
	}

        if (!getArrayValueByString(*surf,"handle",&handle1)) {
        	RETURN_FALSE;
        }
        ZEND_FETCH_RESOURCE(screen,SDL_Surface *,&handle1,-1,le_surface_name,le_surface);

        graphics = new gcn::SDLGraphics();
        graphics->setTarget(screen);
        graphics2array(graphics, return_value TSRMLS_CC);
}
PHP_FUNCTION(guichan_setgraphics) {
	zval *phpgraphics;

    	gcn::SDLGraphics* graphics;
        zval *handle1;
        
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &phpgraphics)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for guichan_setgraphics");
	}

        if (!getArrayValueByString(*phpgraphics,"handle",&handle1)) {
        	RETURN_FALSE;
        }
        ZEND_FETCH_RESOURCE(graphics,gcn::SDLGraphics *,&handle1,-1,le_graphics_name,le_graphics);

        globals::gui->setGraphics(graphics);
}
PHP_FUNCTION(guichan_newinput) {
    	gcn::SDLInput* input;
        
        input = new gcn::SDLInput();
        globals::gui->setInput(input);
        input2array(input, return_value TSRMLS_CC);
}
PHP_FUNCTION(guichan_pushinput) {
	zval *phpinput;
	zval *phpevent;

    	gcn::SDLInput* input;
    	SDL_Event event;
    	zval *handle1;
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &phpinput,&phpevent)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for guichan_pushinput");
	}

        if (!getArrayValueByString(*phpinput,"handle",&handle1)) {
        	RETURN_FALSE;
        }
        ZEND_FETCH_RESOURCE(input,gcn::SDLInput *,&handle1,-1,le_input_name,le_input);
        array2event(*phpevent TSRMLS_CC,&event);

        input->pushInput(event);
}
PHP_FUNCTION(guichan_newcontainer) {
	long x;
	long y;
	long w;
	long h;

    	gcn::Container* top;
        
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll", &x,&y,&w,&h)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for guichan_newcontainer");
	}

        top = new gcn::Container();
        top->setDimension(gcn::Rectangle(x, y, w, h));
        top->setOpaque(false);
        globals::gui->setTop(top);
        container2array(top, return_value TSRMLS_CC);
}
PHP_FUNCTION(guichan_newimagefont) {
	char *filename;
	int filename_length;
	char *glyphs;
	int glyphs_length;

    	gcn::ImageFont* font;
        
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &filename,&filename_length,&glyphs,&glyphs_length)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for guichan_newimagefont");
	}

        font = new gcn::ImageFont(filename, glyphs);
        font2array(font, return_value TSRMLS_CC);
}
PHP_FUNCTION(guichan_setglobalfont) {
	zval *phpfont;

    	gcn::Font* font;
    	zval *handle1;
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &phpfont)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for guichan_setglobalfont");
	}

        if (!getArrayValueByString(*phpfont,"handle",&handle1)) {
        	RETURN_FALSE;
        }
        ZEND_FETCH_RESOURCE(font,gcn::Font *,&handle1,-1,le_font_name,le_font);

        gcn::Widget::setGlobalFont(font);
}
PHP_FUNCTION(guichan_newlabel) {
	zval *phptop;
	char *caption;
	int caption_length;
	long x;
	long y;
	long w;
	long h;

    	gcn::Label* label;
    	gcn::Container* top;
    	
    	zval *handle1;
        
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zsllll", &phptop,&caption,&caption_length,&x,&y,&w,&h)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for guichan_newlabel");
	}

        if (!getArrayValueByString(*phptop,"handle",&handle1)) {
        	RETURN_FALSE;
        }
        ZEND_FETCH_RESOURCE(top,gcn::Container *,&handle1,-1,le_container_name,le_container);

        label = new gcn::Label(caption);
        label->setDimension(gcn::Rectangle(x, y, w, h));
        top->add(label);
        label2array(label, return_value TSRMLS_CC);
}
PHP_FUNCTION(guichan_newbutton) {
	zval *phptop;
	char *caption;
	int caption_length;
	long x;
	long y;
	long w;
	long h;
	zval *mousecallback;
	zval *params;

    	gcn::Button* button;
    	gcn::Container* top;
    	
    	zval *handle1;
    	
    	php_callback *t;
    	zval *obj,*fun,*retval;
    	Uint32 returns;
        
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zsllllzz", &phptop,&caption,&caption_length,&x,&y,&w,&h,&mousecallback,&params)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for guichan_newbutton");
	}

        if (!getArrayValueByString(*phptop,"handle",&handle1)) {
        	RETURN_FALSE;
        }
        ZEND_FETCH_RESOURCE(top,gcn::Container *,&handle1,-1,le_container_name,le_container);

        button = new gcn::Button(caption);
        button->setDimension(gcn::Rectangle(x, y, w, h));
        
        if (mousecallback != NULL) {
            t=(php_callback *)emalloc(sizeof(php_callback));
            Z_ADDREF_P(mousecallback);
    		Z_ADDREF_P(params);
    		t->callback=mousecallback;
			t->params=params;
            php::PhpMouseListener *ml = new php::PhpMouseListener((void *)t);
            button->addMouseListener(ml);
        }
        
        top->add(button);
        button2array(button, return_value TSRMLS_CC);
}
PHP_FUNCTION(guichan_newtextbox) {
	zval *phptop;
	char *caption;
	int caption_length;
	long x;
	long y;
	long w;
	long h;

    	gcn::TextBox* textbox;
    	gcn::Container* top;
    	
    	zval *handle1;
        
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zsllll", &phptop,&caption,&caption_length,&x,&y,&w,&h)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for guichan_newtextbox");
	}

        if (!getArrayValueByString(*phptop,"handle",&handle1)) {
        	RETURN_FALSE;
        }
        ZEND_FETCH_RESOURCE(top,gcn::Container *,&handle1,-1,le_container_name,le_container);

        textbox = new gcn::TextBox(caption);
        textbox->setDimension(gcn::Rectangle(x, y, w, h));
        textbox->setEditable(true);
        top->add(textbox);
        textbox2array(textbox, return_value TSRMLS_CC);
}
PHP_FUNCTION(guichan_newtextfield) {
	zval *phptop;
	char *caption;
	int caption_length;
	long x;
	long y;
	long w;
	long h;
	zval *keycallback;
	zval *params;

    	gcn::TextField* textfield;
    	gcn::Container* top;
    	
    	zval *handle1;
    	
    	php_callback *t;
    	zval *obj,*fun,*retval;
    	Uint32 returns;
        
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zsllllzz", &phptop,&caption,&caption_length,&x,&y,&w,&h,&keycallback,&params)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for guichan_newtextfield");
	}

        if (!getArrayValueByString(*phptop,"handle",&handle1)) {
        	RETURN_FALSE;
        }
        ZEND_FETCH_RESOURCE(top,gcn::Container *,&handle1,-1,le_container_name,le_container);

        textfield = new gcn::TextField(caption);
        textfield->setDimension(gcn::Rectangle(x, y, w, h));
        
        if (keycallback != NULL) {
            t=(php_callback *)emalloc(sizeof(php_callback));
            Z_ADDREF_P(keycallback);
    		Z_ADDREF_P(params);
    		t->callback=keycallback;
			t->params=params;
            php::PhpKeyListner *kl = new php::PhpKeyListner((void *)t);
            textfield->addKeyListener(kl);
        }
        
        top->add(textfield);
        
        textfield2array(textfield, return_value TSRMLS_CC);
}
PHP_FUNCTION(guichan_logic) {
globals::gui->logic();
}
PHP_FUNCTION(guichan_draw) {
    try {
        globals::gui->draw();
    } catch (gcn::Exception e) {
        printf("%s\n",e.getMessage());
        RETURN_FALSE;
    } catch (std::exception e) {
        printf("Std exception: %s\n",e.what());
        RETURN_FALSE;
    } catch (...) {
        printf("Unknown exception\n");
        RETURN_FALSE;
    }
}
PHP_FUNCTION(guichan_quit) {
		if (globals::gui != NULL) { delete globals::gui; }
}
PHP_FUNCTION(guichan_test) {
	zval *surf;
	zval *phpgraphics;
	zval *phptop;
	long x;
	long y;

	SDL_Surface *screen;
	gcn::SDLGraphics* graphics;
	gcn::Container* top;
	zval *handle1,*handle2,*handle3;

	int color;
	SDL_Rect r;
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzll", &surf,&phpgraphics,&phptop,&x,&y)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for guichan_test");
	}

    if (!getArrayValueByString(*surf,"handle",&handle1)) {
    	RETURN_FALSE;
    }
    ZEND_FETCH_RESOURCE(screen,SDL_Surface *,&handle1,-1,le_surface_name,le_surface);
    if (!getArrayValueByString(*phpgraphics,"handle",&handle2)) {
    	RETURN_FALSE;
    }
    ZEND_FETCH_RESOURCE(graphics,gcn::SDLGraphics *,&handle2,-1,le_graphics_name,le_graphics);
    if (!getArrayValueByString(*phptop,"handle",&handle3)) {
    	RETURN_FALSE;
    }
    ZEND_FETCH_RESOURCE(top,gcn::Container *,&handle3,-1,le_container_name,le_container);

    graphics->setColor(gcn::Color(0xff0000));
    graphics->pushClipArea(gcn::Rectangle(0, 0, 600, 500));
    graphics->drawLine(10, 10, 100, 10);
    //graphics->drawRectangle(gcn::Rectangle(0, 0, 250, 250));
    //graphics->drawString("Hello world!", 23, 57);
    graphics->popClipArea();
    SDL_Flip(screen);
}
#ifdef HAVE_SDL_IMAGE
PHP_FUNCTION(img_load) {
	char *file;
	int file_length;

					SDL_Surface *image;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file,&file_length)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for img_load");
	}

					if (NULL == (image = IMG_Load(file))) {
						RETURN_FALSE;
					}
					surf2array(image,return_value TSRMLS_CC);
}
#endif
#ifdef HAVE_SDL_GFX
PHP_FUNCTION(sdlgfx_pixelColor) {
	zval *surf;
	long x;
	long y;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlll", &surf,&x,&y,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			mysdl_error("sdlgfx_pixelColor");
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		pixelColor(s,x,y,(Uint32)color);
}
PHP_FUNCTION(sdlgfx_pixelRGBA) {
	zval *surf;
	long x;
	long y;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllll", &surf,&x,&y,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		pixelRGBA(s,x,y,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_hlineColor) {
	zval *surf;
	long x1;
	long x2;
	long y;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &surf,&x1,&x2,&y,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		hlineColor(s,x1,x2,y,color);
}
PHP_FUNCTION(sdlgfx_hlineRGBA) {
	zval *surf;
	long x1;
	long x2;
	long y;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllllll", &surf,&x1,&x2,&y,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		hlineRGBA(s,x1,x2,y,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_vlineColor) {
	zval *surf;
	long x;
	long y1;
	long y2;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &surf,&x,&y1,&y2,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		vlineColor(s,x,y1,y2,color);
}
PHP_FUNCTION(sdlgfx_vlineRGBA) {
	zval *surf;
	long x;
	long y1;
	long y2;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllllll", &surf,&x,&y1,&y2,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);					
		vlineRGBA(s,x,y1,y2,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_rectangleColor) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllll", &surf,&x1,&y1,&x2,&y2,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		rectangleColor(s,x1,y1,x2,y2,color);
}
PHP_FUNCTION(sdlgfx_rectangleRGBA) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllllll", &surf,&x1,&y1,&x2,&y2,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		rectangleRGBA(s,x1,y1,x2,y2,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_boxColor) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllll", &surf,&x1,&y1,&x2,&y2,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		boxColor(s,x1,y1,x2,y2,color);
}
PHP_FUNCTION(sdlgfx_boxRGBA) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllllll", &surf,&x1,&y1,&x2,&y2,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		boxRGBA(s,x1,y1,x2,y2,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_lineColor) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllll", &surf,&x1,&y1,&x2,&y2,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		lineColor(s,x1,y1,x2,y2,color);
}
PHP_FUNCTION(sdlgfx_lineRGBA) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllllll", &surf,&x1,&y1,&x2,&y2,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		lineRGBA(s,x1,y1,x2,y2,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_aalineColor) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllll", &surf,&x1,&y1,&x2,&y2,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		aalineColor(s,x1,y1,x2,y2,color);
}
PHP_FUNCTION(sdlgfx_aalineRGBA) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllllll", &surf,&x1,&y1,&x2,&y2,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		aalineRGBA(s,x1,y1,x2,y2,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_circleColor) {
	zval *surf;
	long x1;
	long y1;
	long radius;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &surf,&x1,&y1,&radius,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		circleColor(s,x1,y1,radius,color);
}
PHP_FUNCTION(sdlgfx_circleRGBA) {
	zval *surf;
	long x1;
	long y1;
	long radius;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllllll", &surf,&x1,&y1,&radius,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		circleRGBA(s,x1,y1,radius,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_aacircleColor) {
	zval *surf;
	long x1;
	long y1;
	long radius;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &surf,&x1,&y1,&radius,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		aacircleColor(s,x1,y1,radius,color);
}
PHP_FUNCTION(sdlgfx_aacircleRGBA) {
	zval *surf;
	long x1;
	long y1;
	long radius;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllllll", &surf,&x1,&y1,&radius,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		aacircleRGBA(s,x1,y1,radius,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_filledCircleColor) {
	zval *surf;
	long x1;
	long y1;
	long radius;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &surf,&x1,&y1,&radius,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		filledCircleColor(s,x1,y1,radius,color);
}
PHP_FUNCTION(sdlgfx_filledCircleRGBA) {
	zval *surf;
	long x1;
	long y1;
	long radius;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllllll", &surf,&x1,&y1,&radius,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		filledCircleRGBA(s,x1,y1,radius,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_ellipseColor) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllll", &surf,&x1,&y1,&x2,&y2,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		ellipseColor(s,x1,y1,x2,y2,color);
}
PHP_FUNCTION(sdlgfx_ellipseRGBA) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllllll", &surf,&x1,&y1,&x2,&y2,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		ellipseRGBA(s,x1,y1,x2,y2,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_aaellipseColor) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllll", &surf,&x1,&y1,&x2,&y2,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		aaellipseColor(s,x1,y1,x2,y2,color);
}
PHP_FUNCTION(sdlgfx_aaellipseRGBA) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllllll", &surf,&x1,&y1,&x2,&y2,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		aaellipseRGBA(s,x1,y1,x2,y2,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_filledEllipseColor) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllll", &surf,&x1,&y1,&x2,&y2,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		filledEllipseColor(s,x1,y1,x2,y2,color);
}
PHP_FUNCTION(sdlgfx_filledEllipseRGBA) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllllll", &surf,&x1,&y1,&x2,&y2,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		filledEllipseRGBA(s,x1,y1,x2,y2,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_pieColor) {
	zval *surf;
	long x1;
	long y1;
	long rad;
	long start;
	long end;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllll", &surf,&x1,&y1,&rad,&start,&end,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		pieColor(s,x1,y1,rad,start,end,color);
}
PHP_FUNCTION(sdlgfx_pieRGBA) {
	zval *surf;
	long x1;
	long y1;
	long rad;
	long start;
	long end;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllllllll", &surf,&x1,&y1,&rad,&start,&end,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		pieRGBA(s,x1,y1,rad,start,end,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_filledPieColor) {
	zval *surf;
	long x1;
	long y1;
	long rad;
	long start;
	long end;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllll", &surf,&x1,&y1,&rad,&start,&end,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		filledPieColor(s,x1,y1,rad,start,end,color);
}
PHP_FUNCTION(sdlgfx_filledPieRGBA) {
	zval *surf;
	long x1;
	long y1;
	long rad;
	long start;
	long end;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllllllll", &surf,&x1,&y1,&rad,&start,&end,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		filledPieRGBA(s,x1,y1,rad,start,end,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_trigonColor) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long x3;
	long y3;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllllll", &surf,&x1,&y1,&x2,&y2,&x3,&y3,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		trigonColor(s,x1,y1,x2,y2,x3,y3,color);
}
PHP_FUNCTION(sdlgfx_trigonRGBA) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long x3;
	long y3;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllllllll", &surf,&x1,&y1,&x2,&y2,&x3,&y3,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		trigonRGBA(s,x1,y1,x2,y2,x3,y3,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_aatrigonColor) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long x3;
	long y3;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllllll", &surf,&x1,&y1,&x2,&y2,&x3,&y3,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		aatrigonColor(s,x1,y1,x2,y2,x3,y3,color);
}
PHP_FUNCTION(sdlgfx_aatrigonRGBA) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long x3;
	long y3;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllllllll", &surf,&x1,&y1,&x2,&y2,&x3,&y3,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		aatrigonRGBA(s,x1,y1,x2,y2,x3,y3,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_filledTrigonColor) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long x3;
	long y3;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllllll", &surf,&x1,&y1,&x2,&y2,&x3,&y3,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		filledTrigonColor(s,x1,y1,x2,y2,x3,y3,color);
}
PHP_FUNCTION(sdlgfx_filledTrigonRGBA) {
	zval *surf;
	long x1;
	long y1;
	long x2;
	long y2;
	long x3;
	long y3;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllllllllll", &surf,&x1,&y1,&x2,&y2,&x3,&y3,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		filledTrigonRGBA(s,x1,y1,x2,y2,x3,y3,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_polygonColor) {
	zval *surf;
	zval *vx;
	zval *vy;
	long color;

		Sint16 *vx_arr, *vy_arr;
		long vx_arr_n, vy_arr_n,i;
		zval *handle;
		SDL_Surface *s;
		
		zval *data;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzl", &surf,&vx,&vy,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		vx_arr_n=getArrayCount(*vx);
		vy_arr_n=getArrayCount(*vy);
		if (vx_arr_n!=vy_arr_n) {
			// error.
			mysdl_error("sdlgfx_polygonColor: problems with data"); RETURN_FALSE;
		}
		if (vx_arr_n==0) {
			// and, implicity, vy_arr_n==0
			// error
			mysdl_error("sdlgfx_polygonColor: problems with data"); RETURN_FALSE;
		}
		// alloc 2 arrays.
		vx_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		vy_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		
		for (i=0;i<vx_arr_n;i++) {
			if (!getArrayValueByIndex(*vx,i,&data)) {
				mysdl_error("sdlgfx_polygonColor: problems with data"); RETURN_FALSE;
			}
			vx_arr[i]=Z_LVAL_P(data);
			if (!getArrayValueByIndex(*vy,i,&data)) {
				mysdl_error("sdlgfx_polygonColor: problems with data"); RETURN_FALSE;
			}
			vy_arr[i]=Z_LVAL_P(data);						
		}
		// calling.
		RETURN_LONG(polygonColor(s,vx_arr,vy_arr,vx_arr_n,color));
}
PHP_FUNCTION(sdlgfx_polygonRGBA) {
	zval *surf;
	zval *vx;
	zval *vy;
	long r;
	long g;
	long b;
	long a;

		Sint16 *vx_arr, *vy_arr;
		long vx_arr_n, vy_arr_n,i;
		zval *handle;
		SDL_Surface *s;
		
		zval *data;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzllll", &surf,&vx,&vy,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		vx_arr_n=getArrayCount(*vx);
		vy_arr_n=getArrayCount(*vy);
		if (vx_arr_n!=vy_arr_n) {
			// error.
			mysdl_error("sdlgfx_polygonRGBA: problems with data"); RETURN_FALSE;
		}
		if (vx_arr_n==0) {
			// and, implicity, vy_arr_n==0
			// error
			mysdl_error("sdlgfx_polygonRGBA: problems with data"); RETURN_FALSE;
		}
		// alloc 2 arrays.
		vx_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		vy_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		
		for (i=0;i<vx_arr_n;i++) {
			if (!getArrayValueByIndex(*vx,i,&data)) {
				mysdl_error("sdlgfx_polygonRGBA: problems with data"); RETURN_FALSE;
			}
			vx_arr[i]=Z_LVAL_P(data);
			if (!getArrayValueByIndex(*vy,i,&data)) {
				mysdl_error("sdlgfx_polygonRGBA: problems with data"); RETURN_FALSE;
			}
			vy_arr[i]=Z_LVAL_P(data);						
		}
		// calling.
		RETURN_LONG(polygonRGBA(s,vx_arr,vy_arr,vx_arr_n,r,g,b,a));
}
PHP_FUNCTION(sdlgfx_aapolygonColor) {
	zval *surf;
	zval *vx;
	zval *vy;
	long color;

		Sint16 *vx_arr, *vy_arr;
		long vx_arr_n, vy_arr_n,i;
		zval *handle;
		SDL_Surface *s;
		
		zval *data;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzl", &surf,&vx,&vy,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		vx_arr_n=getArrayCount(*vx);
		vy_arr_n=getArrayCount(*vy);
		if (vx_arr_n!=vy_arr_n) {
			// error.
			mysdl_error("sdlgfx_aapolygonColor: problems with data"); RETURN_FALSE;
		}
		if (vx_arr_n==0) {
			// and, implicity, vy_arr_n==0
			// error
			mysdl_error("sdlgfx_aapolygonColor: problems with data"); RETURN_FALSE;
		}
		// alloc 2 arrays.
		vx_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		vy_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		
		for (i=0;i<vx_arr_n;i++) {
			if (!getArrayValueByIndex(*vx,i,&data)) {
				mysdl_error("sdlgfx_aapolygonColor: problems with data"); RETURN_FALSE;
			}
			vx_arr[i]=Z_LVAL_P(data);
			if (!getArrayValueByIndex(*vy,i,&data)) {
				mysdl_error("sdlgfx_aapolygonColor: problems with data"); RETURN_FALSE;
			}
			vy_arr[i]=Z_LVAL_P(data);						
		}
		// calling.
		RETURN_LONG(aapolygonColor(s,vx_arr,vy_arr,vx_arr_n,color));
}
PHP_FUNCTION(sdlgfx_aapolygonRGBA) {
	zval *surf;
	zval *vx;
	zval *vy;
	long r;
	long g;
	long b;
	long a;

		Sint16 *vx_arr, *vy_arr;
		long vx_arr_n, vy_arr_n,i;
		zval *handle;
		SDL_Surface *s;
		
		zval *data;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzllll", &surf,&vx,&vy,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		vx_arr_n=getArrayCount(*vx);
		vy_arr_n=getArrayCount(*vy);
		if (vx_arr_n!=vy_arr_n) {
			// error.
			mysdl_error("sdlgfx_aapolygonRGBA: problems with data"); RETURN_FALSE;
		}
		if (vx_arr_n==0) {
			// and, implicity, vy_arr_n==0
			// error
			mysdl_error("sdlgfx_aapolygonRGBA: problems with data"); RETURN_FALSE;
		}
		// alloc 2 arrays.
		vx_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		vy_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		
		for (i=0;i<vx_arr_n;i++) {
			if (!getArrayValueByIndex(*vx,i,&data)) {
				mysdl_error("sdlgfx_aapolygonRGBA: problems with data"); RETURN_FALSE;
			}
			vx_arr[i]=Z_LVAL_P(data);
			if (!getArrayValueByIndex(*vy,i,&data)) {
				mysdl_error("sdlgfx_aapolygonRGBA: problems with data"); RETURN_FALSE;
			}
			vy_arr[i]=Z_LVAL_P(data);						
		}
		// calling.
		RETURN_LONG(aapolygonRGBA(s,vx_arr,vy_arr,vx_arr_n,r,g,b,a));
}
PHP_FUNCTION(sdlgfx_filledPolygonColor) {
	zval *surf;
	zval *vx;
	zval *vy;
	long color;

		Sint16 *vx_arr, *vy_arr;
		long vx_arr_n, vy_arr_n,i;
		zval *handle;
		SDL_Surface *s;
		
		zval *data;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzl", &surf,&vx,&vy,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		vx_arr_n=getArrayCount(*vx);
		vy_arr_n=getArrayCount(*vy);
		if (vx_arr_n!=vy_arr_n) {
			// error.
			mysdl_error("sdlgfx_aapolygonColor: problems with data"); RETURN_FALSE;
		}
		if (vx_arr_n==0) {
			// and, implicity, vy_arr_n==0
			// error
			mysdl_error("sdlgfx_aapolygonColor: problems with data"); RETURN_FALSE;
		}
		// alloc 2 arrays.
		vx_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		vy_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		
		for (i=0;i<vx_arr_n;i++) {
			if (!getArrayValueByIndex(*vx,i,&data)) {
				mysdl_error("sdlgfx_aapolygonColor: problems with data"); RETURN_FALSE;
			}
			vx_arr[i]=Z_LVAL_P(data);
			if (!getArrayValueByIndex(*vy,i,&data)) {
				mysdl_error("sdlgfx_aapolygonColor: problems with data"); RETURN_FALSE;
			}
			vy_arr[i]=Z_LVAL_P(data);						
		}
		// calling.
		RETURN_LONG(filledPolygonColor(s,vx_arr,vy_arr,vx_arr_n,color));
}
PHP_FUNCTION(sdlgfx_filledPolygonRGBA) {
	zval *surf;
	zval *vx;
	zval *vy;
	long r;
	long g;
	long b;
	long a;

		Sint16 *vx_arr, *vy_arr;
		long vx_arr_n, vy_arr_n,i;
		zval *handle;
		SDL_Surface *s;
		
		zval *data;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzllll", &surf,&vx,&vy,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		vx_arr_n=getArrayCount(*vx);
		vy_arr_n=getArrayCount(*vy);
		if (vx_arr_n!=vy_arr_n) {
			// error.
			mysdl_error("sdlgfx_filledPolygonRGBA: problems with data"); RETURN_FALSE;
		}
		if (vx_arr_n==0) {
			// and, implicity, vy_arr_n==0
			// error
			mysdl_error("sdlgfx_filledPolygonRGBA: problems with data"); RETURN_FALSE;
		}
		// alloc 2 arrays.
		vx_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		vy_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		
		for (i=0;i<vx_arr_n;i++) {
			if (!getArrayValueByIndex(*vx,i,&data)) {
				mysdl_error("sdlgfx_filledPolygonRGBA: problems with data"); RETURN_FALSE;
			}
			vx_arr[i]=Z_LVAL_P(data);
			if (!getArrayValueByIndex(*vy,i,&data)) {
				mysdl_error("sdlgfx_filledPolygonRGBA: problems with data"); RETURN_FALSE;
			}
			vy_arr[i]=Z_LVAL_P(data);						
		}
		// calling.
		RETURN_LONG(filledPolygonRGBA(s,vx_arr,vy_arr,vx_arr_n,r,g,b,a));
}
PHP_FUNCTION(sdlgfx_bezierColor) {
	zval *surf;
	zval *vx;
	zval *vy;
	long s1;
	long color;

		Sint16 *vx_arr, *vy_arr;
		long vx_arr_n, vy_arr_n,i;
		zval *handle;
		SDL_Surface *s;
		
		zval *data;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzll", &surf,&vx,&vy,&s1,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		vx_arr_n=getArrayCount(*vx);
		vy_arr_n=getArrayCount(*vy);
		if (vx_arr_n!=vy_arr_n) {
			// error.
			mysdl_error("sdlgfx_bezierColor: problems with data"); RETURN_FALSE;
		}
		if (vx_arr_n==0) {
			// and, implicity, vy_arr_n==0
			// error
			mysdl_error("sdlgfx_bezierColor: problems with data"); RETURN_FALSE;
		}
		// alloc 2 arrays.
		vx_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		vy_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		
		for (i=0;i<vx_arr_n;i++) {
			if (!getArrayValueByIndex(*vx,i,&data)) {
				mysdl_error("sdlgfx_bezierColor: problems with data"); RETURN_FALSE;
			}
			vx_arr[i]=Z_LVAL_P(data);
			if (!getArrayValueByIndex(*vy,i,&data)) {
				mysdl_error("sdlgfx_bezierColor: problems with data"); RETURN_FALSE;
			}
			vy_arr[i]=Z_LVAL_P(data);						
		}
		// calling.
		RETURN_LONG(bezierColor(s,vx_arr,vy_arr,vx_arr_n,s1,color));
}
PHP_FUNCTION(sdlgfx_bezierRGBA) {
	zval *surf;
	zval *vx;
	zval *vy;
	long s1;
	long r;
	long g;
	long b;
	long a;

		Sint16 *vx_arr, *vy_arr;
		long vx_arr_n, vy_arr_n,i;
		zval *handle;
		SDL_Surface *s;
		
		zval *data;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzzlllll", &surf,&vx,&vy,&s1,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		vx_arr_n=getArrayCount(*vx);
		vy_arr_n=getArrayCount(*vy);
		if (vx_arr_n!=vy_arr_n) {
			// error.
			mysdl_error("sdlgfx_bezierColor: problems with data"); RETURN_FALSE;
		}
		if (vx_arr_n==0) {
			// and, implicity, vy_arr_n==0
			// error
			mysdl_error("sdlgfx_bezierColor: problems with data"); RETURN_FALSE;
		}
		// alloc 2 arrays.
		vx_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		vy_arr=(Sint16 *)emalloc(sizeof(Sint16)*vx_arr_n);
		
		for (i=0;i<vx_arr_n;i++) {
			if (!getArrayValueByIndex(*vx,i,&data)) {
				mysdl_error("sdlgfx_bezierColor: problems with data"); RETURN_FALSE;
			}
			vx_arr[i]=Z_LVAL_P(data);
			if (!getArrayValueByIndex(*vy,i,&data)) {
				mysdl_error("sdlgfx_bezierColor: problems with data"); RETURN_FALSE;
			}
			vy_arr[i]=Z_LVAL_P(data);						
		}
		// calling.
		RETURN_LONG(bezierRGBA(s,vx_arr,vy_arr,vx_arr_n,s1,r,g,b,a));
}
PHP_FUNCTION(sdlgfx_characterColor) {
	zval *surf;
	long x1;
	long y1;
	char *c;
	int c_length;
	long color;

		zval *handle;
		char myc;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllsl", &surf,&x1,&y1,&c,&c_length,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		if (strlen(c)==0) RETURN_FALSE;
		myc=c[0];
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		characterColor(s,x1,y1,myc,color);
}
PHP_FUNCTION(sdlgfx_characterRGBA) {
	zval *surf;
	long x1;
	long y1;
	char *c;
	int c_length;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		char myc;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllsllll", &surf,&x1,&y1,&c,&c_length,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (strlen(c)==0) RETURN_FALSE;
		myc=c[0];
		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		characterRGBA(s,x1,y1,myc,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_stringColor) {
	zval *surf;
	long x1;
	long y1;
	char *text;
	int text_length;
	long color;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllsl", &surf,&x1,&y1,&text,&text_length,&color)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		stringColor(s,x1,y1,text,color);
}
PHP_FUNCTION(sdlgfx_stringRGBA) {
	zval *surf;
	long x1;
	long y1;
	char *text;
	int text_length;
	long r;
	long g;
	long b;
	long a;

		zval *handle;
		SDL_Surface *s;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllsllll", &surf,&x1,&y1,&text,&text_length,&r,&g,&b,&a)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		if (!getArrayValueByString(*surf,"handle",&handle)) {
			RETURN_FALSE;
		}
		ZEND_FETCH_RESOURCE(s,SDL_Surface *,&handle,-1,le_surface_name,le_surface);
		stringRGBA(s,x1,y1,text,r,g,b,a);
}
PHP_FUNCTION(sdlgfx_gfxPrimitivesSetFont) {
php_error(E_WARNING, "function %s() not implemented",get_active_function_name(TSRMLS_C));
}
PHP_FUNCTION(sdlgfx_rotozoomSurface) {
php_error(E_WARNING, "function %s() not implemented",get_active_function_name(TSRMLS_C));
}
PHP_FUNCTION(sdlgfx_rotozoomSurfaceXY) {
php_error(E_WARNING, "function %s() not implemented",get_active_function_name(TSRMLS_C));
}
PHP_FUNCTION(sdlgfx_zoomSurface) {
php_error(E_WARNING, "function %s() not implemented",get_active_function_name(TSRMLS_C));
}
PHP_FUNCTION(sdlgfx_initFramerate) {
	zval *fpsmanager;

		FPSmanager *fps;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &fpsmanager)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		fps=(FPSmanager *)emalloc(sizeof(FPSmanager));
		SDL_initFramerate(fps);
		ZEND_REGISTER_RESOURCE(fpsmanager, fps, le_fpsmanager);
}
PHP_FUNCTION(sdlgfx_setFramerate) {
	zval *fpsmanager;
	int framerate;

		FPSmanager *fps;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &fpsmanager,&framerate)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlgfx_setFramerate");
	}

		ZEND_FETCH_RESOURCE(fps,FPSmanager *,&fpsmanager,-1,le_fpsmanager_name,le_fpsmanager);
		RETURN_LONG(SDL_setFramerate(fps,framerate));
}
PHP_FUNCTION(sdlgfx_getFramerate) {
	zval *fpsmanager;

		FPSmanager *fps;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &fpsmanager)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlgfx_getFramerate");
	}

		ZEND_FETCH_RESOURCE(fps,FPSmanager *,&fpsmanager,-1,le_fpsmanager_name,le_fpsmanager);
		RETURN_LONG(SDL_getFramerate(fps));
}
PHP_FUNCTION(sdlgfx_framerateDelay) {
	zval *fpsmanager;

		FPSmanager *fps;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &fpsmanager)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

		ZEND_FETCH_RESOURCE(fps,FPSmanager *,&fpsmanager,-1,le_fpsmanager_name,le_fpsmanager);	
		SDL_framerateDelay(fps);
}
#endif
#ifdef HAVE_SDL_TTF
PHP_FUNCTION(sdlttf_Init) {
			if (TTF_Init()<0) {
				mysdl_error("Could not initialize SDL_TTF");
				RETURN_FALSE;
			}
			RETURN_TRUE;
}
PHP_FUNCTION(sdlttf_Quit) {
			TTF_Quit();
}
PHP_FUNCTION(sdlttf_WasInit) {
			RETURN_LONG(TTF_WasInit());
}
PHP_FUNCTION(sdlttf_OpenFont) {
	char *file;
	int file_length;
	long ptsize;

			TTF_Font *font;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &file,&file_length,&ptsize)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_OpenFont");
	}

			if (NULL == (font = TTF_OpenFont(file,ptsize))) {
				mysdl_error("Could not open font file");
				RETURN_FALSE;
			}
			ZEND_REGISTER_RESOURCE(return_value, font, le_font);
}
PHP_FUNCTION(sdlttf_OpenFontIndex) {
	char *file;
	int file_length;
	long ptsize;
	long index;

			TTF_Font *font;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &file,&file_length,&ptsize,&index)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_OpenFontIndex");
	}

			if (NULL == (font = TTF_OpenFontIndex(file,ptsize,index))) {
				mysdl_error("Could not open font file");
				RETURN_FALSE;
			}
			ZEND_REGISTER_RESOURCE(return_value, font, le_font);
}
PHP_FUNCTION(sdlttf_OpenFontRW) {
php_error(E_WARNING, "function %s() not implemented",get_active_function_name(TSRMLS_C));
}
PHP_FUNCTION(sdlttf_OpenFontIndexRW) {
php_error(E_WARNING, "function %s() not implemented",get_active_function_name(TSRMLS_C));
}
PHP_FUNCTION(sdlttf_GetFontStyle) {
	zval *font;

			TTF_Font *f;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &font)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_GetFontStyle");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			RETURN_LONG(TTF_GetFontStyle(f));
}
PHP_FUNCTION(sdlttf_SetFontStyle) {
	zval *font;
	long style;

			TTF_Font *f;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl", &font,&style)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for ");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			TTF_SetFontStyle(f,style);
}
PHP_FUNCTION(sdlttf_FontHeight) {
	zval *font;

			TTF_Font *f;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &font)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_FontHeight");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			RETURN_LONG(TTF_FontHeight(f));
}
PHP_FUNCTION(sdlttf_FontAscent) {
	zval *font;

			TTF_Font *f;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &font)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_FontAscent");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			RETURN_LONG(TTF_FontAscent(f));
}
PHP_FUNCTION(sdlttf_FontDescent) {
	zval *font;

			TTF_Font *f;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &font)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_FontDescent");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			RETURN_LONG(TTF_FontDescent(f));
}
PHP_FUNCTION(sdlttf_FontLineSkip) {
	zval *font;

			TTF_Font *f;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &font)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_FontLineSkip");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			RETURN_LONG(TTF_FontLineSkip(f));
}
PHP_FUNCTION(sdlttf_FontFaces) {
	zval *font;

			TTF_Font *f;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &font)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_FontFaces");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			RETURN_LONG(TTF_FontFaces(f));
}
PHP_FUNCTION(sdlttf_FontFaceIsFixedWidth) {
	zval *font;

			TTF_Font *f;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &font)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_FontFaceIsFixedWidth");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			RETURN_LONG(TTF_FontFaceIsFixedWidth(f));
}
PHP_FUNCTION(sdlttf_FontFaceFamilyName) {
	zval *font;

			TTF_Font *f;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &font)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_FontFaceFamilyName");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			RETURN_STRING(TTF_FontFaceFamilyName(f),1);
}
PHP_FUNCTION(sdlttf_FontFaceStyleName) {
	zval *font;

			TTF_Font *f;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &font)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_FontFaceStyleName");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			RETURN_STRING(TTF_FontFaceStyleName(f),1);
}
PHP_FUNCTION(sdlttf_GlyphMetrics) {
	zval *font;
	long ch;
	zval *minx;
	zval *maxx;
	zval *miny;
	zval *maxy;
	zval *advance;

			TTF_Font *f;
			int minx1,maxx1,miny1,maxy1,advance1,ret;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlzzzzz", &font,&ch,&minx,&maxx,&miny,&maxy,&advance)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_GlyphMetrics");
	}

			minx1=maxx1=miny1=maxy1=advance1=ret=0;
			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			ret=TTF_GlyphMetrics(f,ch,&minx1,&maxx1,&miny1,&maxy1,&advance1);
			if (!ret) {
				ZVAL_LONG(minx,minx1);
				ZVAL_LONG(maxx,maxx1);
				ZVAL_LONG(miny,miny1);
				ZVAL_LONG(maxy,maxy1);
				ZVAL_LONG(advance,advance1);
				RETURN_LONG(ret);
			} else {
				php_printf("%s\n",TTF_GetError());
				RETURN_FALSE;
			}
}
PHP_FUNCTION(sdlttf_SizeText) {
	zval *font;
	char *text;
	int text_length;

			TTF_Font *f;
			int ret,width,height;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &font,&text,&text_length)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_SizeText");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			ret=TTF_SizeText(f,text,&width,&height);
			array_init(return_value);	
			add_assoc_long(return_value, "w", width);
			add_assoc_long(return_value, "h", height);
}
PHP_FUNCTION(sdlttf_SizeUTF8) {
	zval *font;
	char *text;
	int text_length;

			TTF_Font *f;
			int ret,width,height;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &font,&text,&text_length)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_SizeUTF8");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			ret=TTF_SizeUTF8(f,text,&width,&height);
			array_init(return_value);	
			add_assoc_long(return_value, "w", width);
			add_assoc_long(return_value, "h", height);
}
PHP_FUNCTION(sdlttf_SizeUNICODE) {
	zval *font;
	char *text;
	int text_length;

			TTF_Font *f;
			int ret,width,height;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &font,&text,&text_length)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_SizeUNICODE");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			ret=TTF_SizeUNICODE(f,(Uint16 *)text,&width,&height);
			array_init(return_value);	
			add_assoc_long(return_value, "w", width);
			add_assoc_long(return_value, "h", height);
}
PHP_FUNCTION(sdlttf_RenderText_Solid) {
	zval *font;
	char *text;
	int text_length;
	long r;
	long g;
	long b;

			TTF_Font *f;					
			SDL_Surface *dest;					
			SDL_Color c;
			c.r=r; c.g=g; c.b=b;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zslll", &font,&text,&text_length,&r,&g,&b)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_RenderText_Solid");
	}

			if (strlen(text)==0) RETURN_FALSE;
			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			dest=TTF_RenderText_Solid(f,text,c);
			surf2array(dest,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdlttf_RenderUTF8_Solid) {
	zval *font;
	char *text;
	int text_length;
	long r;
	long g;
	long b;

			TTF_Font *f;					
			SDL_Surface *dest;					
			SDL_Color c;
			c.r=r; c.g=g; c.b=b;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zslll", &font,&text,&text_length,&r,&g,&b)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_RenderUTF8_Solid");
	}

			if (strlen(text)==0) RETURN_FALSE;
			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			dest=TTF_RenderUTF8_Solid(f,text,c);
			surf2array(dest,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdlttf_RenderUNICODE_Solid) {
	zval *font;
	char *text;
	int text_length;
	long r;
	long g;
	long b;

			TTF_Font *f;					
			SDL_Surface *dest;					
			SDL_Color c;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zslll", &font,&text,&text_length,&r,&g,&b)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_RenderUNICODE_Solid");
	}

			if (strlen(text)==0) RETURN_FALSE;
			c.r=r; c.g=g; c.b=b;
			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			dest=TTF_RenderUNICODE_Solid(f,(Uint16 *)text,c);
			surf2array(dest,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdlttf_RenderGlyph_Solid) {
	zval *font;
	long ch;
	long r;
	long g;
	long b;

			TTF_Font *f;					
			SDL_Surface *dest;					
			SDL_Color c;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &font,&ch,&r,&g,&b)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_RenderGlyph_Solid");
	}

			c.r=r; c.g=g; c.b=b;
			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			dest=TTF_RenderGlyph_Solid(f,ch,c);
			surf2array(dest,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdlttf_RenderText_Shaded) {
	zval *font;
	char *text;
	int text_length;
	long r1;
	long g1;
	long b1;
	long r2;
	long g2;
	long b2;

			TTF_Font *f;					
			SDL_Surface *dest;					
			SDL_Color c1,c2;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zsllllll", &font,&text,&text_length,&r1,&g1,&b1,&r2,&g2,&b2)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_RenderText_Shaded");
	}

			if (strlen(text)==0) RETURN_FALSE;
			c1.r=r1; c1.g=g1; c1.b=b1;
			c2.r=r2; c2.g=g2; c2.b=b2;
			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			dest=TTF_RenderText_Shaded(f,text,c1,c2);
			surf2array(dest,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdlttf_RenderUTF8_Shaded) {
	zval *font;
	char *text;
	int text_length;
	long r1;
	long g1;
	long b1;
	long r2;
	long g2;
	long b2;

			TTF_Font *f;					
			SDL_Surface *dest;					
			SDL_Color c1,c2;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zsllllll", &font,&text,&text_length,&r1,&g1,&b1,&r2,&g2,&b2)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_RenderUTF8_Shaded");
	}

			if (strlen(text)==0) RETURN_FALSE;
			c1.r=r1; c1.g=g1; c1.b=b1;
			c2.r=r2; c2.g=g2; c2.b=b2;
			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			dest=TTF_RenderUTF8_Shaded(f,text,c1,c2);
			surf2array(dest,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdlttf_RenderUNICODE_Shaded) {
	zval *font;
	char *text;
	int text_length;
	long r1;
	long g1;
	long b1;
	long r2;
	long g2;
	long b2;

			TTF_Font *f;					
			SDL_Surface *dest;					
			SDL_Color c1,c2;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zsllllll", &font,&text,&text_length,&r1,&g1,&b1,&r2,&g2,&b2)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_RenderUNICODE_Shaded");
	}

			if (strlen(text)==0) RETURN_FALSE;
			c1.r=r1; c1.g=g1; c1.b=b1;
			c2.r=r2; c2.g=g1; c2.b=b2;
			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			dest=TTF_RenderUNICODE_Shaded(f,(Uint16 *)text,c1,c2);
			surf2array(dest,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdlttf_RenderGlyph_Shaded) {
	zval *font;
	long ch;
	long r1;
	long g1;
	long b1;
	long r2;
	long g2;
	long b2;

			TTF_Font *f;					
			SDL_Surface *dest;					
			SDL_Color c1,c2;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zlllllll", &font,&ch,&r1,&g1,&b1,&r2,&g2,&b2)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_RenderGlyph_Shaded");
	}

			c1.r=r1; c1.g=g1; c1.b=b1;
			c2.r=r2; c2.g=g2; c2.b=b2;
			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			dest=TTF_RenderGlyph_Shaded(f,ch,c1,c2);
			surf2array(dest,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdlttf_RenderText_Blended) {
	zval *font;
	char *text;
	int text_length;
	long r;
	long g;
	long b;

			TTF_Font *f;					
			SDL_Surface *dest;					
			SDL_Color c;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zslll", &font,&text,&text_length,&r,&g,&b)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_RenderText_Blended");
	}

			if (strlen(text)==0) RETURN_FALSE;
			c.r=r; c.g=g; c.b=b;
			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			dest=TTF_RenderText_Blended(f,text,c);
			surf2array(dest,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdlttf_RenderUTF8_Blended) {
	zval *font;
	char *text;
	int text_length;
	long r;
	long g;
	long b;

			TTF_Font *f;					
			SDL_Surface *dest;					
			SDL_Color c;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zslll", &font,&text,&text_length,&r,&g,&b)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_RenderUTF8_Blended");
	}

			if (strlen(text)==0) RETURN_FALSE;
			c.r=r; c.g=g; c.b=b;
			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			dest=TTF_RenderUTF8_Blended(f,text,c);
			surf2array(dest,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdlttf_RenderUNICODE_Blended) {
	zval *font;
	char *text;
	int text_length;
	long r;
	long g;
	long b;

			TTF_Font *f;					
			SDL_Surface *dest;					
			SDL_Color c;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zslll", &font,&text,&text_length,&r,&g,&b)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_RenderUNICODE_Blended");
	}

			if (strlen(text)==0) RETURN_FALSE;
			c.r=r; c.g=g; c.b=b;
			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			dest=TTF_RenderUNICODE_Blended(f,(Uint16 *)text,c);
			surf2array(dest,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdlttf_RenderGlyph_Blended) {
	zval *font;
	long ch;
	long r;
	long g;
	long b;

			TTF_Font *f;					
			SDL_Surface *dest;					
			SDL_Color c;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zllll", &font,&ch,&r,&g,&b)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_RenderGlyph_Blended");
	}

			c.r=r; c.g=g; c.b=b;
			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			dest=TTF_RenderGlyph_Blended(f,ch,c);
			surf2array(dest,return_value TSRMLS_CC);
}
PHP_FUNCTION(sdlttf_CloseFont) {
	zval *font;

			TTF_Font *f;
			long handle;
			
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &font)==FAILURE) {
	    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error passing parameters for sdlttf_CloseFont");
	}

			ZEND_FETCH_RESOURCE(f, TTF_Font *, &font, -1, le_font_name, le_font);
			TTF_CloseFont(f);
			handle = Z_LVAL_P(font);
			zend_list_delete(handle);
}
#endif

/*******************************
 * End Functions Code
 *******************************/